At any point, you can submit your answers by collecting them and uploading them to the class site.
No answers yet collected
If requested by your instructor, please identify here the people from whom you received assistance on this assignment.
14 Exercises: Moving past two inputs
NOTE: These are all just idea sketches.
id: “fir-wish-kayak” created: “Wed Mar 4 17:07:51 2026” attribution: TBA —
Exercise 14. 1 Solving with the gradient
STILL USE THE GRADIENT, BUT LOOK AT WHETHER THE FUNCTION OUTPUT is greater or lesser than the desired value, then step forward or backward respectively.
id: “sheep-put-cotton” created: “Wed Mar 4 17:08:15 2026” attribution: TBA —
Exercise 14. 2 Curse of dimensionality Divide an n-dimensional cube into blocks with edge length 1/3 that of the cube. For 250-dimensional space, there are roughly 1.9e119 cubes, more than the number of particles in the universe. A 15 x 20 pixel image is a point in a 300-dimensional space. To fill that space with data is impossible.
id: “maple-ride-pencil” created: “Wed Mar 4 17:09:57 2026” attribution: TBA —
Exercise 14. 3 Who pays?
GfromBeta <- function(a, b) {
(2/a)*beta(a+b, a+b)/(beta(a,a)*beta(b,b))
}0.35 on 0-1 scale corresponds to 1.4% of households. These were the households who paid income tax in 1913, with the deductable of $3000. (There were 357,600 tax forms filed. The total income of all these people was $3,900,000,000. About 80% of them paid tax. The total tax paid was $28,000,000.)
The reported Gini coefficient in 2023 was 0.48. Using the beta distribution as our model, this corresponds to dbeta(frac, 1, 10).
We don’t know the median income in 1913. In 2024 it was $83,750. For dbeta(frac, 1,10), the median occurs at frac = 0.065. That provides a scale for converting
frac = 0.065 * income / 83750
id: “cat-know-scarf” created: “Wed Mar 4 17:08:52 2026” attribution: TBA —
Exercise 14. 4 Construct the whole QALYs versus cost, with optimal allocation between Natal and Cancer. Turn this into an “average cost” per QALY. Will this have a maximum? Show that near the maximum the function is flat.
I”M NOT SURE the above will work. Find some optimality
id: “elbow-leave-jacket” created: “Wed Mar 4 17:09:26 2026” attribution: TBA —
Exercise 14. 5 Do the calculations to produce the years-saved versus cost function from Figure 13.7. Or maybe just the average years saved, that is, how to compute an expectation value.
id: “beech-refer-hat” created: “Wed Mar 4 17:13:00 2026” attribution: TBA —
Exercise 14. 6 In-class discussion: The gradient field. In optimization, we are walking on a field of gradient flowers. Each flower has a small stamen that points in a particular compass direction. We can, however, only see the stamen of the flower at hand. At each step, we examine that flower, then walk in the direction indicated for a small distance. Examining the flower at our new position gives a new direction to walk in. We continue in this way, following an uphill path from flower to flower.
id: “giraffe-bite-ring” created: “Wed Mar 4 17:13:33 2026” attribution: TBA —
Exercise 14. 7 Show the vector field and ask students to follow the gradient. Then switch to the Shiny app, which lets them evaluate the field one step at a time.
Exercise 14. 8 SHOW THE numerical value of the “alignment” (that is, cos(theta)) Then mention how it is very closely related to the “correlation coefficient”. ALIGNMENT AND ANGLE are very closely related. The cosine of the ANGLE is the ALIGNMENT. PERPENDICULAR is an alignment of 0. Parallel is an alignment of 1. Anti-parallel is an alignment of -1.
Exercise 14. 9 Alignment of random vectors in high-dimensional space. And what is a random vector. Maybe a 3-d plot of random, unit-length vectors. How to create a unit-length vector.
Exercise 14. 12 From the Scottish Parliament data … Organization of the bills ::: {#fig-bills-3d}
open3d()
points3d(x = b1, y = b2, z = b3)
# close3d()Organizations of the MPs
open3d()
points3d(x = a1, y = a2, z = a3)
# close3d()14.1 fawn-buy-ring
Exercise 14. 10
library(nnet)
## An example for gradient descent
# See how much the error is reduced for each step.
ir <- rbind(iris3[,,1],iris3[,,2],iris3[,,3])
targets <- class.ind( c(rep("s", 50), rep("c", 50), rep("v", 50)) )
samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
ir1 <- nnet(ir[samp,], targets[samp,], size = 2, rang = 0.1,
decay = 5e-4, maxit = 200)# weights: 19
initial value 56.859690
iter 10 value 49.032500
iter 20 value 25.205399
iter 30 value 25.133619
iter 40 value 25.009035
iter 50 value 21.350578
iter 60 value 17.917557
iter 70 value 17.634484
iter 80 value 17.467275
iter 90 value 17.409314
iter 100 value 17.315538
iter 110 value 17.281577
iter 120 value 17.280779
iter 130 value 17.277436
iter 140 value 17.247995
iter 150 value 16.307137
iter 160 value 6.057714
iter 170 value 2.063076
iter 180 value 1.572468
iter 190 value 1.145869
iter 200 value 0.926270
final value 0.926270
stopped after 200 iterations
test.cl <- function(true, pred) {
true <- max.col(true)
cres <- max.col(pred)
table(true, cres)
}
test.cl(targets[-samp,], predict(ir1, ir[-samp,])) cres
true 1 2 3
1 22 0 3
2 0 25 0
3 0 0 25
Res <- list()
for (k in 1:50) {
set.seed(101) # start it at the same point each time.
net <- nnet(ir, targets, size = 10, maxit = k)
Res[[k]] <- test.cl(targets, predict(net, ir))
}# weights: 83
initial value 134.259063
final value 121.821695
stopped after 2 iterations
# weights: 83
initial value 134.259063
final value 121.821695
stopped after 2 iterations
# weights: 83
initial value 134.259063
final value 116.219168
stopped after 3 iterations
# weights: 83
initial value 134.259063
final value 106.513386
stopped after 4 iterations
# weights: 83
initial value 134.259063
final value 97.223532
stopped after 5 iterations
# weights: 83
initial value 134.259063
final value 93.514443
stopped after 6 iterations
# weights: 83
initial value 134.259063
final value 90.577370
stopped after 7 iterations
# weights: 83
initial value 134.259063
final value 83.200467
stopped after 8 iterations
# weights: 83
initial value 134.259063
final value 73.834550
stopped after 9 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 61.774194
stopped after 10 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 53.444941
stopped after 11 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 51.959400
stopped after 12 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 51.310973
stopped after 13 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 51.020471
stopped after 14 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 50.537225
stopped after 15 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 49.578206
stopped after 16 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 45.145614
stopped after 17 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 45.065500
stopped after 18 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
final value 44.344836
stopped after 19 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 40.443855
stopped after 20 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 38.955837
stopped after 21 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 35.540018
stopped after 22 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 30.764894
stopped after 23 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 29.686056
stopped after 24 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 26.633024
stopped after 25 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 24.683648
stopped after 26 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 20.825131
stopped after 27 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 13.520313
stopped after 28 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
final value 6.537500
stopped after 29 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 5.000084
stopped after 30 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 4.588833
stopped after 31 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 4.329794
stopped after 32 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 4.116945
stopped after 33 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 3.926932
stopped after 34 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 3.734507
stopped after 35 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 3.333863
stopped after 36 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 3.166655
stopped after 37 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 2.972446
stopped after 38 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
final value 2.812099
stopped after 39 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.497851
stopped after 40 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.193654
stopped after 41 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.045349
stopped after 42 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.019976
stopped after 43 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.014433
stopped after 44 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.013960
stopped after 45 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.011660
stopped after 46 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.010015
stopped after 47 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.009437
stopped after 48 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
final value 2.007364
stopped after 49 iterations
# weights: 83
initial value 134.259063
iter 10 value 61.774194
iter 20 value 40.443855
iter 30 value 5.000084
iter 40 value 2.497851
iter 50 value 2.006451
final value 2.006451
stopped after 50 iterations
14.2 sheep-put-cotton
Exercise 14. 11 Curse of dimensionality Divide an n-dimensional cube into blocks with edge length 1/3 that of the cube. For 250-dimensional space, there are roughly 1.9e119 cubes, more than the number of particles in the universe. A 15 x 20 pixel image is a point in a 300-dimensional space. To fill that space with data is impossible.