text:
# 12.1 The ellipse  (Page 9/16)

 Page 9 / 16

$4{x}^{2}+16{y}^{2}=1$

$\frac{{\left(x-2\right)}^{2}}{49}+\frac{{\left(y-4\right)}^{2}}{25}=1$

$\frac{{\left(x-2\right)}^{2}}{{7}^{2}}+\frac{{\left(y-4\right)}^{2}}{{5}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(9,4\right),\left(-5,4\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(2,9\right),\left(2,-1\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(2+2\sqrt{6},4\right),\left(2-2\sqrt{6},4\right).$

$\frac{{\left(x-2\right)}^{2}}{81}+\frac{{\left(y+1\right)}^{2}}{16}=1$

$\frac{{\left(x+5\right)}^{2}}{4}+\frac{{\left(y-7\right)}^{2}}{9}=1$

$\frac{{\left(x+5\right)}^{2}}{{2}^{2}}+\frac{{\left(y-7\right)}^{2}}{{3}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(-5,10\right),\left(-5,4\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(-3,7\right),\left(-7,7\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(-5,7+\sqrt{5}\right),\left(-5,7-\sqrt{5}\right).$

$\frac{{\left(x-7\right)}^{2}}{49}+\frac{{\left(y-7\right)}^{2}}{49}=1$

$4{x}^{2}-8x+9{y}^{2}-72y+112=0$

$\frac{{\left(x-1\right)}^{2}}{{3}^{2}}+\frac{{\left(y-4\right)}^{2}}{{2}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(4,4\right),\left(-2,4\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(1,6\right),\left(1,2\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(1+\sqrt{5},4\right),\left(1-\sqrt{5},4\right).$

$9{x}^{2}-54x+9{y}^{2}-54y+81=0$

$4{x}^{2}-24x+36{y}^{2}-360y+864=0$

$\frac{{\left(x-3\right)}^{2}}{{\left(3\sqrt{2}\right)}^{2}}+\frac{{\left(y-5\right)}^{2}}{{\left(\sqrt{2}\right)}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(3+3\sqrt{2},5\right),\left(3-3\sqrt{2},5\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(3,5+\sqrt{2}\right),\left(3,5-\sqrt{2}\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(7,5\right),\left(-1,5\right).$

$4{x}^{2}+24x+16{y}^{2}-128y+228=0$

$4{x}^{2}+40x+25{y}^{2}-100y+100=0$

$\frac{{\left(x+5\right)}^{2}}{{\left(5\right)}^{2}}+\frac{{\left(y-2\right)}^{2}}{{\left(2\right)}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(0,2\right),\left(-10,2\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(-5,4\right),\left(-5,0\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(-5+\sqrt{21},2\right),\left(-5-\sqrt{21},2\right).$

${x}^{2}+2x+100{y}^{2}-1000y+2401=0$

$4{x}^{2}+24x+25{y}^{2}+200y+336=0$

$\frac{{\left(x+3\right)}^{2}}{{\left(5\right)}^{2}}+\frac{{\left(y+4\right)}^{2}}{{\left(2\right)}^{2}}=1;\text{\hspace{0.17em}}$ Endpoints of major axis $\text{\hspace{0.17em}}\left(2,-4\right),\left(-8,-4\right).\text{\hspace{0.17em}}$ Endpoints of minor axis $\text{\hspace{0.17em}}\left(-3,-2\right),\left(-3,-6\right).\text{\hspace{0.17em}}$ Foci at $\text{\hspace{0.17em}}\left(-3+\sqrt{21},-4\right),\left(-3-\sqrt{21},-4\right).$

$9{x}^{2}+72x+16{y}^{2}+16y+4=0$

For the following exercises, find the foci for the given ellipses.

$\frac{{\left(x+3\right)}^{2}}{25}+\frac{{\left(y+1\right)}^{2}}{36}=1$

Foci $\text{\hspace{0.17em}}\left(-3,-1+\sqrt{11}\right),\left(-3,-1-\sqrt{11}\right)$

$\frac{{\left(x+1\right)}^{2}}{100}+\frac{{\left(y-2\right)}^{2}}{4}=1$

${x}^{2}+{y}^{2}=1$

Focus $\text{\hspace{0.17em}}\left(0,0\right)$

${x}^{2}+4{y}^{2}+4x+8y=1$

$10{x}^{2}+{y}^{2}+200x=0$

Foci $\text{\hspace{0.17em}}\left(-10,30\right),\left(-10,-30\right)$

## Graphical

For the following exercises, graph the given ellipses, noting center, vertices, and foci.

$\frac{{x}^{2}}{25}+\frac{{y}^{2}}{36}=1$

$\frac{{x}^{2}}{16}+\frac{{y}^{2}}{9}=1$

Center $\text{\hspace{0.17em}}\left(0,0\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(4,0\right),\left(-4,0\right),\left(0,3\right),\left(0,-3\right),\text{\hspace{0.17em}}$ Foci $\text{\hspace{0.17em}}\left(\sqrt{7},0\right),\left(-\sqrt{7},0\right)$

$4{x}^{2}+9{y}^{2}=1$

$81{x}^{2}+49{y}^{2}=1$

Center $\text{\hspace{0.17em}}\left(0,0\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(\frac{1}{9},0\right),\left(-\frac{1}{9},0\right),\left(0,\frac{1}{7}\right),\left(0,-\frac{1}{7}\right),\text{\hspace{0.17em}}$ Foci $\text{\hspace{0.17em}}\left(0,\frac{4\sqrt{2}}{63}\right),\left(0,-\frac{4\sqrt{2}}{63}\right)$

$\frac{{\left(x-2\right)}^{2}}{64}+\frac{{\left(y-4\right)}^{2}}{16}=1$

$\frac{{\left(x+3\right)}^{2}}{9}+\frac{{\left(y-3\right)}^{2}}{9}=1$

Center $\text{\hspace{0.17em}}\left(-3,3\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(0,3\right),\left(-6,3\right),\left(-3,0\right),\left(-3,6\right),\text{\hspace{0.17em}}$ Focus $\text{\hspace{0.17em}}\left(-3,3\right)\text{\hspace{0.17em}}$

Note that this ellipse is a circle. The circle has only one focus, which coincides with the center.

$\frac{{x}^{2}}{2}+\frac{{\left(y+1\right)}^{2}}{5}=1$

$4{x}^{2}-8x+16{y}^{2}-32y-44=0$

Center $\text{\hspace{0.17em}}\left(1,1\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(5,1\right),\left(-3,1\right),\left(1,3\right),\left(1,-1\right),\text{\hspace{0.17em}}$ Foci $\text{\hspace{0.17em}}\left(1,1+4\sqrt{3}\right),\left(1,1-4\sqrt{3}\right)$

${x}^{2}-8x+25{y}^{2}-100y+91=0$

${x}^{2}+8x+4{y}^{2}-40y+112=0$

Center $\text{\hspace{0.17em}}\left(-4,5\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(-2,5\right),\left(-6,4\right),\left(-4,6\right),\left(-4,4\right),\text{\hspace{0.17em}}$ Foci $\text{\hspace{0.17em}}\left(-4+\sqrt{3},5\right),\left(-4-\sqrt{3},5\right)$

$64{x}^{2}+128x+9{y}^{2}-72y-368=0$

$16{x}^{2}+64x+4{y}^{2}-8y+4=0$

Center $\text{\hspace{0.17em}}\left(-2,1\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(0,1\right),\left(-4,1\right),\left(-2,5\right),\left(-2,-3\right),\text{\hspace{0.17em}}$ Foci $\text{\hspace{0.17em}}\left(-2,1+2\sqrt{3}\right),\left(-2,1-2\sqrt{3}\right)$

$100{x}^{2}+1000x+{y}^{2}-10y+2425=0$

$4{x}^{2}+16x+4{y}^{2}+16y+16=0$

Center $\text{\hspace{0.17em}}\left(-2,-2\right),\text{\hspace{0.17em}}$ Vertices $\text{\hspace{0.17em}}\left(0,-2\right),\left(-4,-2\right),\left(-2,0\right),\left(-2,-4\right),\text{\hspace{0.17em}}$ Focus $\text{\hspace{0.17em}}\left(-2,-2\right)$

For the following exercises, use the given information about the graph of each ellipse to determine its equation.

Center at the origin, symmetric with respect to the x - and y -axes, focus at $\text{\hspace{0.17em}}\left(4,0\right),$ and point on graph $\text{\hspace{0.17em}}\left(0,3\right).$

Center at the origin, symmetric with respect to the x - and y -axes, focus at $\text{\hspace{0.17em}}\left(0,-2\right),$ and point on graph $\text{\hspace{0.17em}}\left(5,0\right).$

$\frac{{x}^{2}}{25}+\frac{{y}^{2}}{29}=1$

Center at the origin, symmetric with respect to the x - and y -axes, focus at $\text{\hspace{0.17em}}\left(3,0\right),$ and major axis is twice as long as minor axis.

Center $\text{\hspace{0.17em}}\left(4,2\right)$ ; vertex $\text{\hspace{0.17em}}\left(9,2\right)$ ; one focus: $\text{\hspace{0.17em}}\left(4+2\sqrt{6},2\right)$ .

$\frac{{\left(x-4\right)}^{2}}{25}+\frac{{\left(y-2\right)}^{2}}{1}=1$

Center $\text{\hspace{0.17em}}\left(3,5\right)$ ; vertex $\text{\hspace{0.17em}}\left(3,11\right)$ ; one focus:

Center $\text{\hspace{0.17em}}\left(-3,4\right)$ ; vertex $\text{\hspace{0.17em}}\left(1,4\right)$ ; one focus: $\text{\hspace{0.17em}}\left(-3+2\sqrt{3},4\right)$

$\frac{{\left(x+3\right)}^{2}}{16}+\frac{{\left(y-4\right)}^{2}}{4}=1$

For the following exercises, given the graph of the ellipse, determine its equation.

$\frac{{x}^{2}}{81}+\frac{{y}^{2}}{9}=1$

$\frac{{\left(x+2\right)}^{2}}{4}+\frac{{\left(y-2\right)}^{2}}{9}=1$

## Extensions

For the following exercises, find the area of the ellipse. The area of an ellipse is given by the formula $\text{\hspace{0.17em}}\text{Area}=a\cdot b\cdot \pi .$

$\frac{{\left(x-3\right)}^{2}}{9}+\frac{{\left(y-3\right)}^{2}}{16}=1$

$\frac{{\left(x+6\right)}^{2}}{16}+\frac{{\left(y-6\right)}^{2}}{36}=1$

$\frac{{\left(x+1\right)}^{2}}{4}+\frac{{\left(y-2\right)}^{2}}{5}=1$

$4{x}^{2}-8x+9{y}^{2}-72y+112=0$

$9{x}^{2}-54x+9{y}^{2}-54y+81=0$

## Real-world applications

Find the equation of the ellipse that will just fit inside a box that is 8 units wide and 4 units high.

Find the equation of the ellipse that will just fit inside a box that is four times as wide as it is high. Express in terms of $\text{\hspace{0.17em}}h,$ the height.

$\frac{{x}^{2}}{4{h}^{2}}+\frac{{y}^{2}}{\frac{1}{4}{h}^{2}}=1$

An arch has the shape of a semi-ellipse (the top half of an ellipse). The arch has a height of 8 feet and a span of 20 feet. Find an equation for the ellipse, and use that to find the height to the nearest 0.01 foot of the arch at a distance of 4 feet from the center.

An arch has the shape of a semi-ellipse. The arch has a height of 12 feet and a span of 40 feet. Find an equation for the ellipse, and use that to find the distance from the center to a point at which the height is 6 feet. Round to the nearest hundredth.

$\frac{{x}^{2}}{400}+\frac{{y}^{2}}{144}=1$ . Distance = 17.32 feet

A bridge is to be built in the shape of a semi-elliptical arch and is to have a span of 120 feet. The height of the arch at a distance of 40 feet from the center is to be 8 feet. Find the height of the arch at its center.

A person in a whispering gallery standing at one focus of the ellipse can whisper and be heard by a person standing at the other focus because all the sound waves that reach the ceiling are reflected to the other person. If a whispering gallery has a length of 120 feet, and the foci are located 30 feet from the center, find the height of the ceiling at the center.

Approximately 51.96 feet

A person is standing 8 feet from the nearest wall in a whispering gallery. If that person is at one focus, and the other focus is 80 feet away, what is the length and height at the center of the gallery?

use the properties of logarithms to rewrite as a single logarithmic expression 2+log base 5 t divided by log base 5 17
(cos²x +tan²x)÷(sec²x+cos²x)
Solve the problem 3x^2_2x+4=0
can anyone recommend an app or. website to help me refresh my knowledge and abilities? I stopped learning more about calc and trig in the 90's
if 6x=-2 find value of 6/x
l don't know
Aman
I don't know
Aman
l don't know
Aman
I don't know
Aman
x=.333333333334, so 6/x= 18±
scott
x=.33333333334± 6/x=18±
scott
that is strange, I don't remember inserting the À. the result I got was x= 3333333334± 6/x=18±
scott
I need glasses
scott
X=(-1÷3) X equals minus one third
Melvin
how can I get the answer if don't know it
x=-3
Dani
-18
Nwaneri
if sin15°=√p, express the following in terms of p
I am learning and does someone have the time to tell me what or where this particular equation would be used?
scott
prove sin²x+cos²x=3+cos4x
the difference between two signed numbers is -8.if the minued is 5,what is the subtrahend
the difference between two signed numbers is -8.if the minuend is 5.what is the subtrahend
jeramie
what are odd numbers
numbers that leave a remainder when divided by 2
Thorben
1,3,5,7,... 99,...867
Thorben
7%2=1, 679%2=1, 866245%2=1
Thorben
the third and the seventh terms of a G.P are 81 and 16, find the first and fifth terms.
if a=3, b =4 and c=5 find the six trigonometric value sin
Ans
pls how do I factorize x⁴+x³-7x²-x+6=0
in a function the input value is called
how do I test for values on the number line
if a=4 b=4 then a+b=
a+b+2ab
Kin
commulative principle
a+b= 4+4=8
Mimi
If a=4 and b=4 then we add the value of a and b i.e a+b=4+4=8.
Tariq

format: plain


text:
from tensorflow import keras

from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt

from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPool2D
from keras.optimizers import RMSprop
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ReduceLROnPlateau

# Exercise: Convolutional Neural Networks¶

In the lectures, we have been introduced to a variety of neural network layers: 1) dense layers, 2) dropout layers, 3) convolutional layers and 4) pooling layers. With this set of layers, it is already possible to achieve new state-of-the-art performance i.e. $$\geq$$ 99.7% accuracy on the MNIST dataset. In this exercise, we will walk through an example of a simple convolutional network with the main objective of familiarising oneself with a general machine learning workflow.

First let us load and prepare the data set. Notice that we have split the data into training, validation and testing sets. In addition, we have reshaped the images to include an additional dimension which is required for convolutional layers. Convolutional layers take as input images from one or more channels and output images to one or more channels. The additional dimension stores the information from these multiple channels.

(x_train, y_train),(x_test, y_test) = keras.datasets.mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

x_train = x_train.reshape(-1,28,28,1)
x_test = x_test.reshape(-1,28,28,1)

x_train, x_val, y_train, y_val = train_test_split(
x_train, y_train, test_size = 1/6, random_state=42)

print('x_train.shape =', x_train.shape)
print('y_train.shape =', y_train.shape)
print('x_val.shape =', x_val.shape)
print('y_val.shape =', y_val.shape)
print('x_test.shape =', x_test.shape)
print('y_test.shape =', y_test.shape)

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 0s 0us/step
x_train.shape = (50000, 28, 28, 1)
y_train.shape = (50000,)
x_val.shape = (10000, 28, 28, 1)
y_val.shape = (10000,)
x_test.shape = (10000, 28, 28, 1)
y_test.shape = (10000,)

## A simple convolutional network¶

In this first part, we simply want to try out a very simple convolutional neural network and compare its performance with a dense network with similar number of parameters.

def make_conv_model():
model = Sequential()

activation ='relu', input_shape = (28,28,1)))
activation ='relu'))

model.compile(optimizer=optimizer,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model

def make_dense_model():
model = Sequential()

model.compile(optimizer=optimizer,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model

simple_conv_model = make_conv_model()
dense_model = make_dense_model()
simple_conv_model.summary()
dense_model.summary()

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 28, 28, 10)        260
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 28, 28, 10)        2510
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 14, 14, 10)        0
_________________________________________________________________
flatten (Flatten)            (None, 1960)              0
_________________________________________________________________
dense (Dense)                (None, 64)                125504
_________________________________________________________________
dropout (Dropout)            (None, 64)                0
_________________________________________________________________
dense_1 (Dense)              (None, 10)                650
=================================================================
Total params: 128,924
Trainable params: 128,924
Non-trainable params: 0
_________________________________________________________________
Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
flatten_1 (Flatten)          (None, 784)               0
_________________________________________________________________
dense_2 (Dense)              (None, 512)               401920
_________________________________________________________________
dropout_1 (Dropout)          (None, 512)               0
_________________________________________________________________
dense_3 (Dense)              (None, 256)               131328
_________________________________________________________________
dropout_2 (Dropout)          (None, 256)               0
_________________________________________________________________
dense_4 (Dense)              (None, 10)                2570
=================================================================
Total params: 535,818
Trainable params: 535,818
Non-trainable params: 0
_________________________________________________________________

Now let us train the models and compare its validation and test accuracies.

epochs = 40
batch_size = 86

simple_conv_history = simple_conv_model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_data=(x_val, y_val), verbose=0)
dense_history = dense_model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_data=(x_val, y_val),verbose=0)

Having trained the models, we can now evaluate and plot the accuracies on the validation and training sets.

simple_conv_test_loss, simple_conv_test_acc = simple_conv_model.evaluate(x_test, y_test)
dense_test_loss, dense_test_acc = dense_model.evaluate(x_test, y_test)

plt.plot(dense_history.history["accuracy"], "b--",label="dense training accuracy")
plt.plot(dense_history.history["val_accuracy"], "b-",label="dense val accuracy")
plt.axhline(dense_test_acc, color="k", linestyle=":", label="dense test accuracy")
plt.plot(simple_conv_history.history["accuracy"], "g--",label="simple conv training accuracy")
plt.plot(simple_conv_history.history["val_accuracy"], "g-",label="simple conv val accuracy")
plt.axhline(simple_conv_test_acc,color="k", linestyle="--", label="simple conv test accuracy")
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0.94, 1.005)
plt.legend()

313/313 [==============================] - 1s 2ms/step - loss: 0.0432 - accuracy: 0.9907
313/313 [==============================] - 1s 2ms/step - loss: 0.1149 - accuracy: 0.9806

We do indeed see that the validation accuracies are an extremely good approximation of the test accuracies as one would expect if the datasets were split randomly and each set still contains sufficient number of samples. However, in practice, if we were selecting hyperparameters based on the validation data, the accuracies would then be biased towards the validation set and then the true generalisation accuracy of the model should then be evaluated using the testing set. On the hand, we do see that models are overfitted since the training accuracies are exceeding the validation and test accuracies significantly.

On a separate note, we do see that the convolutional layers do improve the performance substantially despite having similar number of parameters. This is particular to this problem since image classification are often insensitive towards translations which are well handled by convolutional layers.

## Data Augmentation¶

It is obvious that with more data, we would be able to achieve better performances. One reason for this is that with more data, the problem of overfitting is reduced. Hence, there have been many elaborate schemes for expanding a dataset. For image classification tasks such as here, a common approach is simply to augment the data with small translations and rotations of the original data samples. This works for our case because we know that even if a digit is rotated and translated, the classification of that digit would not change. This can be done easily using the following function from keras.

datagen = ImageDataGenerator(
featurewise_center=False,  # set input mean to 0 over the dataset
samplewise_center=False,  # set each sample mean to 0
featurewise_std_normalization=False,  # divide inputs by std of the dataset
samplewise_std_normalization=False,  # divide each input by its std
zca_whitening=False,  # apply ZCA whitening
rotation_range=10,  # randomly rotate images in the range (degrees)
zoom_range = 0.1, # Randomly zoom image
width_shift_range=0.1,  # randomly shift images horizontally
height_shift_range=0.1,  # randomly shift images vertically
horizontal_flip=False,  # randomly flip images
vertical_flip=False)  # randomly flip images

datagen.fit(x_train.reshape(-1,28,28,1))

simple_conv_model = make_conv_model()

epochs = 40
batch_size = 86
simple_conv_aug_history = simple_conv_model.fit(
datagen.flow(x_train,y_train, batch_size=batch_size),
epochs = epochs, validation_data = (x_val,y_val),
steps_per_epoch=x_train.shape[0]//batch_size, verbose=0)

Now lets reevaluate our test and validation accuracies.

simple_conv_aug_test_loss, simple_conv_aug_test_acc = simple_conv_model.evaluate(x_test, y_test)

plt.plot(simple_conv_aug_history.history["accuracy"], "g--",label="simple conv aug training accuracy")
plt.plot(simple_conv_aug_history.history["val_accuracy"], "g-",label="simple conv aug val accuracy")
plt.axhline(simple_conv_aug_test_acc,color="k", linestyle="--", label="simple conv aug test accuracy")
plt.axhline(simple_conv_test_acc,color="r", linestyle="--", label="simple conv test accuracy")
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0.94, 1.005)
plt.legend()

313/313 [==============================] - 1s 2ms/step - loss: 0.0209 - accuracy: 0.9937

With the data set augmentation, we do indeed see some improvement in the final test or generalisation accuracy. Notice also that the training accuracy is now below the validation and test accuracy. This is because in each epoch, new data samples are generated via translations and rotations such that it is extremely difficult for the model to overfit.

## Learning rate reduction¶

To further improve accuracies, it can sometimes be helpful to reduce the learning as one approach convergence. There are many different scheme to achieve this. A common method is to monitor a certain metric, for instance the validation accuracy, and to reduce the learning rate when the chosen metric is not improving for a certain number of epochs. Here, we monitor the validation accuracy and reduce the learning rate by half when the accuracy is not improving after 3 epochs.

learning_rate_reduction = ReduceLROnPlateau(monitor='val_accuracy',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001)

epochs = 30
batch_size = 86

simple_conv_model = make_conv_model()

simple_conv_aug_lr_history = simple_conv_model.fit(
datagen.flow(x_train,y_train, batch_size=batch_size),
epochs = epochs, validation_data = (x_val,y_val),
steps_per_epoch=x_train.shape[0]//batch_size,
callbacks=[learning_rate_reduction],
verbose=0)

Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00022: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00025: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

simple_conv_aug_lr_test_loss, simple_conv_aug_lr_test_acc = simple_conv_model.evaluate(x_test, y_test)

plt.plot(simple_conv_aug_lr_history.history["accuracy"], "g:",label="simple conv aug lr training accuracy")
plt.plot(simple_conv_aug_lr_history.history["val_accuracy"], "g-",label="simple conv aug lr val accuracy")
plt.axhline(simple_conv_aug_lr_test_acc,color="k", linestyle="--", label="simple conv aug lr test accuracy")
plt.axhline(simple_conv_aug_test_acc,color="g", linestyle="--", label="simple conv aug test accuracy")
plt.axhline(simple_conv_test_acc,color="r", linestyle="--", label="simple conv test accuracy")
plt.xlabel("epochs")
plt.ylabel("accuracy")
plt.ylim(0.94, 1.005)
plt.legend()

313/313 [==============================] - 1s 2ms/step - loss: 0.0180 - accuracy: 0.9944

## Committee Machine¶

Finally, a possible way to improve the accuracy is simply to train multiple models and then to average the output from the various models. This is a form of committee machine known as ensemble averaging. The functional api of keras provides a very simple way to average across multiple models. This might take a while so it would be helpful to run it on google colab or some other external servers.

# Create an ensemble of models
models = [make_conv_model() for i in range(5)]

epochs = 30
batch_size = 86

# Fit the model
history = [model.fit(datagen.flow(x_train,y_train, batch_size=batch_size),
epochs = epochs, validation_data = (x_val,y_val),
steps_per_epoch=x_train.shape[0]//batch_size,
callbacks=[learning_rate_reduction], verbose=0
) for model in models]

for i, model in enumerate(models):
print("model", i, "loss and accuracy:", model.evaluate(x_test, y_test))

Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00013: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00022: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00025: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.

Epoch 00028: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.

Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00020: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00024: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00018: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00027: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00009: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00018: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00028: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00022: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00026: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.
313/313 [==============================] - 1s 2ms/step - loss: 0.0195 - accuracy: 0.9932
model 0 loss and accuracy: [0.01947448030114174, 0.9932000041007996]
313/313 [==============================] - 1s 2ms/step - loss: 0.0182 - accuracy: 0.9938
model 1 loss and accuracy: [0.01823325641453266, 0.9937999844551086]
313/313 [==============================] - 1s 2ms/step - loss: 0.0192 - accuracy: 0.9935
model 2 loss and accuracy: [0.01915612816810608, 0.9934999942779541]
313/313 [==============================] - 1s 2ms/step - loss: 0.0197 - accuracy: 0.9938
model 3 loss and accuracy: [0.019724765792489052, 0.9937999844551086]
313/313 [==============================] - 1s 2ms/step - loss: 0.0212 - accuracy: 0.9930
model 4 loss and accuracy: [0.02119877189397812, 0.9929999709129333]

Now we can average across the models and evaluate the ensemble average as follows:

x = keras.layers.Input(shape=(28,28,1))
yi = [model(x) for model in models]
y = keras.layers.Average()(yi)
Committee = keras.models.Model(inputs=x, outputs=y)
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

committee_conv_loss, committee_conv_acc = Committee.evaluate(x_test,y_test)

313/313 [==============================] - 1s 3ms/step - loss: 0.0145 - accuracy: 0.9950

Comparing with the accuracy of the individual models, we do see an increase in the performance over each individual model.

## State-of-the-art performance¶

Now lets see if we can push the accuracy of our models close to the state-of-the-art performance of about 99.7%. We shall use all the techniques so far, except that we would use a larger convolutional model with more layers.

def make_deep_conv_model():
model = Sequential()

activation ='relu', input_shape = (28,28,1)))
activation ='relu'))

activation ='relu'))
activation ='relu'))

# optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0)

model.compile(optimizer=optimizer,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model

# Create an ensemble of models
deep_models = [make_deep_conv_model() for i in range(5)]

epochs = 30
batch_size = 86

# Fit the model
history = [model.fit(datagen.flow(x_train,y_train, batch_size=batch_size),
epochs = epochs, validation_data = (x_val,y_val),
steps_per_epoch=x_train.shape[0]//batch_size,
callbacks=[learning_rate_reduction], verbose=0
) for model in deep_models]

for i, model in enumerate(deep_models):
print("model", i, "loss and accuracy:", model.evaluate(x_test, y_test))

x = keras.layers.Input(shape=(28,28,1))
yi = [model(x) for model in deep_models]
y = keras.layers.Average()(yi)
deep_Committee = keras.models.Model(inputs=x, outputs=y)
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

deep_committee_conv_loss, deep_committee_conv_acc = deep_Committee.evaluate(x_test,y_test)

Epoch 00019: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00025: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00029: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00010: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00017: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00020: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00027: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.

Epoch 00030: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.

Epoch 00008: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00019: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00025: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.

Epoch 00028: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.

Epoch 00015: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00022: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00026: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00029: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.

Epoch 00010: ReduceLROnPlateau reducing learning rate to 0.0005000000237487257.

Epoch 00014: ReduceLROnPlateau reducing learning rate to 0.0002500000118743628.

Epoch 00023: ReduceLROnPlateau reducing learning rate to 0.0001250000059371814.

Epoch 00026: ReduceLROnPlateau reducing learning rate to 6.25000029685907e-05.

Epoch 00029: ReduceLROnPlateau reducing learning rate to 3.125000148429535e-05.
313/313 [==============================] - 1s 2ms/step - loss: 0.0117 - accuracy: 0.9957
model 0 loss and accuracy: [0.011735166423022747, 0.9957000017166138]
313/313 [==============================] - 1s 2ms/step - loss: 0.0094 - accuracy: 0.9966
model 1 loss and accuracy: [0.009402372874319553, 0.9965999722480774]
313/313 [==============================] - 1s 2ms/step - loss: 0.0091 - accuracy: 0.9971
model 2 loss and accuracy: [0.009083079174160957, 0.9970999956130981]
313/313 [==============================] - 1s 3ms/step - loss: 0.0121 - accuracy: 0.9962
model 3 loss and accuracy: [0.012146216817200184, 0.9962000250816345]
313/313 [==============================] - 1s 3ms/step - loss: 0.0111 - accuracy: 0.9971
model 4 loss and accuracy: [0.01112508587539196, 0.9970999956130981]
313/313 [==============================] - 2s 5ms/step - loss: 0.0076 - accuracy: 0.9974

x = keras.layers.Input(shape=(28,28,1))
yi = [model(x) for model in deep_models]
y = keras.layers.Average()(yi)
deep_Committee = keras.models.Model(inputs=x, outputs=y)
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

deep_committee_conv_loss, deep_committee_conv_acc = deep_Committee.evaluate(x_test,y_test)

313/313 [==============================] - 2s 5ms/step - loss: 0.0076 - accuracy: 0.9974

We get quite close to the state of the art performance (check https://en.wikipedia.org/wiki/MNIST_database). The question is how much further can one go. Is it possible to get 100% accuracy? Actually it should not be possible, because some samples in the dataset might be wrongly labelled or is completely unreadable even for a human. Lets look at some of the misclassified samples in the testing set.

predictions = np.argmax(deep_Committee.predict(x_test), axis=1)

misclassified_samples = np.where(predictions != y_test)[0]
print("number of misclassified samples =", misclassified_samples.shape[0])
plt.figure(figsize=(8,8))

for i, s in enumerate(misclassified_samples):
plt.subplot(6,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(x_test[s][:,:,0], cmap=plt.cm.binary)
plt.xlabel(str(y_test[s]), color='blue', fontsize=20)
plt.ylabel(str(predictions[s]), color='red', fontsize=20, rotation=0)
plt.tight_layout()

number of misclassified samples = 26

In the above plot, we have shown the true prediction in blue and the network prediction in red. Inspecting some of the figures, we might actually agree with the network prediction on some occassions.


text:
# Can we prove $Aut(S_g) , g \geq 2$ is finite in the following way ?

I was trying to prove that $Aut( S_g$), g$\geq 2$ [ orientation preserving isometries ] is finite in the following way :

For fixed $M$ ( positive ) there are finitely many , say $k$ number of simple closed geodesics ( with repeated multiplicities ), say $c_1...c_k$ with length $\leq M$. Consider the group $Aut(S_g$) acting on this finite set $S$ of geodesics ( it acts, since an isometry preserve the length of geodesics ). Now the number of permutations of $S$ is $k!$ ( k-factorial ). So, if we can prove that :

Lemma : An automorphism of surface of genus $\geq 2$ is fully and uniquely determined by its action on finitely many ( say $k$ ,depending on genus g ) simple closed geodesics ( forming the set $S$ ),

then we can have only $k!$ permutations of $S$ and hence we would have only at most $k!$ distinct automorphism of $S_g$, if the Lemma is true . Is the lemma true and easily provable ? Or is there any other way to prove the main question ( $Aut(S_g)$ is finite ) ?

-

The answer is yes. It's a little easier if we consider oriented geodesics (which is fine for your argument). Let $\alpha$ and $\beta$ be two oriented simple closed curves on $S_g$ that intersect once. Let $a$ and $b$ be geodesics that are homotopic to $\alpha$ and $\beta$, respectively. Then $a$ and $b$ only intersect once, say at a point $x \in S$. Now let two isometries $f_1,f_2 : S \rightarrow S$ be given. Assume that $f_1(a) = f_2(a)$ and $f_1(b) = f_2(b)$ (as oriented geodesics). I claim that $f_1=f_2$. Indeed, it is clear that $f_1(x)=f_2(x)$. Moreover, if $v$ is the unit tangent vector at $x$ pointing in the direction of $a$ (remember, $a$ has an orientation), then we also know that $f_1(v)=f_2(v)$. Since an element of $SO(2)$ is determined by its value at a single non-zero vector, this implies that both the values and the derivatives of $f_1$ and $f_2$ agree at $x$, and a standard result of Riemannian geometry (using the exponential map) says that then $f_1 = f_2$.
This implies that you can take $S$ to be the set of all geodesics whose lengths are at most the lengths of $a$ or $b$.
@ Dr Puttman : Thak you for your very clear answer . I would just take $M$ big enough such that there is at least a pair of once-intersecting geodesics. – Analysis Now Jan 30 '11 at 18:47


text:
# A number theory problem by Rahul Chowdhury

Number Theory Level 2

Let $$t_n$$ denote the number of integer sided triangles with distinct sides chosen from $$\{1,2,3,4, \ldots, n\}$$. Then $$t_{20} - t_{19} =$$

×