-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes-vision-notes.txt
80 lines (63 loc) · 2.59 KB
/
shapes-vision-notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
// Helper functions available (provided by the dependencies we include above):
var canvas1 = Draw(50, 50, true) // semicolon at end of line is optional
// parameters are width, height, whether to display the canvas in the output
loadImage(canvas1, "assets/beach.png")
var canvas2 = Draw(50, 50, true)
loadImage(canvas2, "assets/beach2.png")
// distance compares two images
//images must be the same size
canvas1.distance(canvas2)
// some available distributions (see http://docs.webppl.org/en/master/distributions.html and https://webppl.readthedocs.io/en/master/sample.html)
flip() or flip(p) e.g. flip(0.7) (70% likelihood of heads)
uniform(min, max) e.g. uniform(0, 10) (random value between 0 and 10, each option equally likely)
gaussian(mean, standardDeviation) e.g. gaussian(0, 3)
randomInteger(max) e.g. randomInteger(10) (random integer from 0 to 9)
For more WebPPL documentation, see https://webppl.readthedocs.io/en/master/
*/
// ** IF YOU WANT TO UPLOAD AN IMAGE, UPLOAD IT TO THE /assets FOLDER; you can drag and drop it at https://github.com/p-ai-org/p-generative/tree/main/assets
// (I put beach.png there as an example -- see how small it is! smaller images will be easier for us to process;
// you can shrink any image you want, or edit any image you want, using https://www.photopea.com/) **
/* demoing some of our functions */
/*drawShapes(canvas1, [
{
shape: 'rect',
dims: [20, 20],
x: 90, // distance from left edge
y: 60, // distance from top edge
angle: 35 // angle is in degrees
},
{
shape: 'rect',
dims: [20, 10],
x: 30,
y: 55,
angle: 0
}
], "white", "cyan", 1.0)*/
/*
var canvas2 = Draw(100, 100, false)
loadImage(canvas2, "assets/beach.png")
display('Distance to original: ' + canvas2.distance(canvas1))
*/
/*
// a generative modeling demo
var model = function() {
// generate data
var die1 = randomInteger(6) + 1; // random integer from 1 to 6
var die2 = randomInteger(6) + 1;
// constrain the data
// condition(die1 + die2 == 8)
// factor(-Infinity) // => 10^-inf = 0
// factor(0) // => 0 => 10^0 = 1
// factor(-100.0/(die1 + die2))
factor(Math.pow(.94, -(die1 + die2)))
// for the sake of this model, we only care about one of our variables (the value of one of our dice)
return die1;
}
// infer generated values that match the constraint
var roll = Infer({ model: model });
// visualize: inference recognizes that for the dice to sum to 8, the first die must have rolled a 2,3,4,5 or 6
viz(roll);
*/
// notes moved to notion fifth and sixth meeting notes