QuestionQuestion

Task I: (MNIST classification using Batch GD (BGD) driven softmax regression)

-Download mnist folder from Canvas
-The provided code will extract and pre-process the dataset
-The provided code also does the post-processing including thresholding, accuracy etc.
-For your ease, following lines are left empty for you to fill.

err =
gradients =
theta =
y_predict =

1.1. Use BGD and complete the model
1.2. Explain in detail (step by step) the whole process in your own words, including:

-raw data
-pre-processing (both X and Y (onehot encoded))
-Number of iterations/epochs
-Calculation of above 4 lines

1.3. Test the model on test data and comment on the results in detail

NOTE that batch gradient descent computes the gradient using the whole dataset

TASK II: (MNIST classification using Stochastic GD (SGD) driven softmax regression)

-Download mnist.pkl.gz from Canvas
-The provided code will extract and pre-process the dataset
-The provided code also does the post-processing including thresholding, accuracy etc.
-For your ease, following lines are left empty for you to fill.

err =
gradients =
Updated theta =
y_predict =

2.1. Use SGD and complete the model
2.2. Explain in detail (step by step) the whole process in your own words, including:

-raw data
-Number of iterations/epochs
-pre-processing (mini-batches)
-Calculation of above 4 lines
-difference between task 1 and 2, in terms of accuracy

2.3. Test the model on test data and comment on the results in detail

NOTE that stochastic gradient descent computes the gradient using small batches

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Functions for downloading and reading MNIST data (deprecated).

This module and all its submodules are deprecated.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import collections
import gzip
import os

import numpy
from six.moves import urllib
from six.moves import xrange # pylint: disable=redefined-builtin

from tensorflow.python.framework import dtypes
from tensorflow.python.framework import random_seed
from tensorflow.python.platform import gfile
from tensorflow.python.util.deprecation import deprecated

_Datasets = collections.namedtuple('_Datasets', ['train', 'validation', 'test'])

# CVDF mirror of http://yann.lecun.com/exdb/mnist/
DEFAULT_SOURCE_URL = 'https://storage.googleapis.com/cvdf-datasets/mnist/'


def _read32(bytestream):
dt = numpy.dtype(numpy.uint32).newbyteorder('>')
return numpy.frombuffer(bytestream.read(4), dtype=dt)[0]


@deprecated(None, 'Please use tf.data to implement this functionality.')
def _extract_images(f):
"""Extract the images into a 4D uint8 numpy array [index, y, x, depth].

Args:
    f: A file object that can be passed into a gzip reader.

Returns:
    data: A 4D uint8 numpy array [index, y, x, depth].

Raises:
    ValueError: If the bytestream does not start with 2051.

"""
print('Extracting', f.name)
with gzip.GzipFile(fileobj=f) as bytestream:
    magic = _read32(bytestream)
    if magic != 2051:
      raise ValueError('Invalid magic number %d in MNIST image file: %s' %
                      (magic, f.name))
    num_images = _read32(bytestream)
    rows = _read32(bytestream)
    cols = _read32(bytestream)
    buf = bytestream.read(rows * cols * num_images)
    data = numpy.frombuffer(buf, dtype=numpy.uint8)
    data = data.reshape(num_images, rows, cols, 1)
    return data


@deprecated(None, 'Please use tf.one_hot on tensors.')
def _dense_to_one_hot(labels_dense, num_classes):
"""Convert class labels from scalars to one-hot vectors."""
num_labels = labels_dense.shape[0]
index_offset = numpy.arange(num_labels) * num_classes
labels_one_hot = numpy.zeros((num_labels, num_classes))
labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1
return labels_one_hot


@deprecated(None, 'Please use tf.data to implement this functionality.')
def _extract_labels(f, one_hot=False, num_classes=10):
"""Extract the labels into a 1D uint8 numpy array [index].

Args:
    f: A file object that can be passed into a gzip reader.
    one_hot: Does one hot encoding for the result.
    num_classes: Number of classes for the one hot encoding.

Returns:
    labels: a 1D uint8 numpy array.

Raises:
    ValueError: If the bystream doesn't start with 2049.
"""
print('Extracting', f.name)
with gzip.GzipFile(fileobj=f) as bytestream:
    magic = _read32(bytestream)
    if magic != 2049:
      raise ValueError('Invalid magic number %d in MNIST label file: %s' %
                      (magic, f.name))
    num_items = _read32(bytestream)
    buf = bytestream.read(num_items)
    labels = numpy.frombuffer(buf, dtype=numpy.uint8)
    if one_hot:
      return _dense_to_one_hot(labels, num_classes)
    return labels...

By purchasing this solution you'll be able to access the following files:
Solution1.zip and Solution2.docx.

50% discount

Hours
Minutes
Seconds
$60.00 $30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats