from sklearn import datasets
iris = datasets.load_iris()
iris.data[:,0].min(), iris.data[:,0].max()
(4.2999999999999998, 7.9000000000000004)
ptp(iris.data[:,0])
3.6000000000000005
Normalize the features
index_0 = (iris.data[:,0] - iris.data[:,0].min())/ptp(iris.data[:,0])
index_1 = (iris.data[:,1] - iris.data[:,1].min())/ptp(iris.data[:,1])
space = zeros((512,512))
a = linspace(0, 20, 11)
print a
a[[2,3,5, 1]]
[ 0. 2. 4. 6. 8. 10. 12. 14. 16. 18. 20.]
array([ 4., 6., 10., 2.])
a[[2,3,5, 1]] +=1
print a
[ 0. 3. 5. 7. 8. 11. 12. 14. 16. 18. 20.]
a[[2,3,5, 1]] +=1
print a
[ 0. 4. 6. 8. 8. 12. 12. 14. 16. 18. 20.]
space[50 + (index_0*450).astype(int),50 + (index_1*450).astype(int)] += 1
imshow(space, cmap='gray', aspect='auto')
gcf().set_figheight(12)
gcf().set_figwidth(12)
from scipy.ndimage.filters import gaussian_filter
gspace = gaussian_filter(space, 7)
imshow(gspace)
gcf().set_figheight(9)
gcf().set_figwidth(9)
Ex,Ey = gradient(gspace)
figure(figsize=(12,10))
#imshow(gspace)
quiver(Ex[::20],Ey[::20])
<matplotlib.quiver.Quiver at 0x41edb90>
imshow(Ex)
<matplotlib.image.AxesImage at 0x5ee2b90>
imshow(Ey)
<matplotlib.image.AxesImage at 0x5f09990>
n = 30000
dt = 1e-1
r = zeros((n,2))
v = zeros((n,2))
a = zeros((n,2))
r[0] = [256, 256]
v[0] = [0, -2.0]
damp = 0.9999
q = 5500
m = 0.5
for i in range(n - 1):
E = array([Ex[int(r[i][0]), int(r[i][1])], Ey[int(r[i][0]), int(r[i][1])]])
a[i+1] = q*E/m
v[i+1] = damp * (v[i] + a[i+1]*dt)
r[i+1] = r[i] + v[i+1]*dt
figure(figsize=(12,10))
imshow(gspace.T)
#quiver(Ex[::],Ey[::])
plot(*r.T, lw=3, c= 'w')
xlim((0, 512))
ylim((0, 512))
(0, 512)
plot(v)
gcf().set_figwidth(16)
vel = hypot(*v.T)
plot(hypot(*v.T))
gcf().set_figwidth(16)
Kinetic energy:
$E_\text{k} =\tfrac{1}{2} mv^2$
Ek = 0.5 * m * hypot(*v.T)**2
plot(Ek)
[<matplotlib.lines.Line2D at 0x6ffe410>]
import icsound
ics = icsound.icsound()
ics.start_engine()
%%csound
givalue = 10
%%csound
print givalue
ics.print_log()
rtaudio: ALSA module enabled rtmidi: ALSA Raw MIDI module enabled --Csound version 6.03.2 (double samples) May 29 2014 graphics suppressed, ascii substituted 0dBFS level = 1.0 orch now loaded audio buffered in 256 sample-frame blocks ALSA output: total buffer size: 1024, period size: 256 writing 512 sample blks of 64-bit floats to dac SECTION 1: instr 0: givalue = 10.000
ics.fill_table(1, Ek)
%%csound
chn_k "freq", 1
instr 1
kfreq chnget "freq"
asig poscil 1/45, kfreq, 1
outs asig, asig
endin
ics.send_score("i 1 0 -1")
ics.set_channel("freq", 1.0)
ics.set_channel("freq", 0.5)
ics.start_record("one_particle.wav")
ics.stop_record()
ics.send_score("i -1 0 -1")
!aplay one_particle.wav
Playing WAVE 'one_particle.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
By: Andrés Cabrera mantaraya36@gmail.com
For Course MAT 240F at UCSB
This ipython notebook is licensed under the CC-BY-NC-SA license: http://creativecommons.org/licenses/by-nc-sa/4.0/