Exemplo n.º 1
0
def runui():
#--------------------------------------------------------------------------------------------------
    from animate import launchui
    def config(*animate):
        from animate import cfg_anim
        from myutil import quickui
        ffmt = '{0:.3f}'.format
        Q = quickui.cbook
        return quickui.configuration(
            Q.Ctransf(dict,multi=True),
            ('syst',dict(sel=None),
             Q.Ctransf(
                partial(
                  RandomWalk,
                  N=400,
                  )
                ),
             ('stepg',dict(tooltip='Specification of the normal 0-mean random step'),
              Q.Ctransf(
                  partial(
                    bvn,
                    vx=3.1,
                    vy=2.8,
                    cor=.5
                    )
                  ),
              ('vx',dict(accept=Q.i),
               Q.Cbase.LinScalar(vmin=.1,vmax=1.,nval=1000,vtype=float,fmt=ffmt)
               ),
              ('vy',dict(accept=Q.i),
               Q.Cbase.LinScalar(vmin=.1,vmax=1.,nval=1000,vtype=float,fmt=ffmt)
               ),
              ('cor',dict(accept=Q.i),
               Q.Cbase.LinScalar(vmin=0.,vmax=1.,nval=1000,vtype=float,fmt=ffmt)
               )
              ),
             ('N',dict(accept=Q.i),
              Q.Cbase.LinScalar(step=1,vmin=100,vmax=1000,vtype=int)
              ),
             ),
            ('animate',dict(sel=False))+
            cfg_anim(
              *animate,
               modifier=dict(
                save=dict(
                  filename='randwalk.mp4',
                  metadata=dict(
                    title='A random walk',
                    ),
                  ),
                )
               ),
            )
    def axes(view):
        view.figure.set_size_inches((8,12),forward=True)
        view.make_grid(2,1)
        return view[0,0].make_axes(),view[1,0].make_axes()
    launchui(config,axes=axes,width=600)
Exemplo n.º 2
0
def runui():
#--------------------------------------------------------------------------------------------------
    from animate import launchui
    from myutil import set_qtbinding; set_qtbinding('pyqt4')  
    datasection = testdatagenerator().configurator
    def config(*animate):
        from myutil import quickui
        GPRegrTypes = (
            ('constant',None),
            ('linear',None),
            ('quadratic',None),
            )
        GPKernels = (
            ('absolute_exponential','exp(-theta|d|)'),
            ('squared_exponential','exp(-theta|d|^2)'),
            #'generalized_exponential',
            ('cubic',None),
            ('linear',None),
            )
        def GPconv(regr=None,corr=None,**ka):
            return GP(regr=GPRegrTypes[regr][0],corr=GPKernels[corr][0],**ka)
        Q = quickui.cbook
        return quickui.configuration(
            Q.Ctransf(partial(dict,logscale=False,nsample=100,clevel=.95,gpmean=False)),
            ('syst',dict(anchor=True),Q.Ctransf(partial(GPconv,regr=2,corr=1,theta0=.1,thetaL_r=.01,thetaU_r=100.,nugget=.01,random_start=1)),
             datasection(),
             ('regr',dict(accept=Q.i,tooltip='Regression type'),Q.Cbase.Set(options=GPRegrTypes)),
             ('corr',dict(accept=Q.i,tooltip='GP kernel'),Q.Cbase.Set(options=GPKernels)),
             ('nugget',dict(accept=Q.i,tooltip='Tychonov regularisation'),Q.Cbase.LogScalar(vmin=.0001,vmax=1000)),
             ('theta0',dict(accept=Q.i,tooltip='Larger means faster decrease of prior correlation when distance increases'),Q.Cbase.LogScalar(vmin=.001,vmax=10.)),
             ('thetaL_r',dict(accept=Q.i,tooltip='Ratio to theta0 of lower bound of parameter space exploration'),Q.Cbase.LogScalar(vmin=.001,vmax=1.)),
             ('thetaU_r',dict(accept=Q.i,tooltip='Ratio to theta0 of upper bound of parameter space exploration'),Q.Cbase.LogScalar(vmin=1.,vmax=1000.)),
             ('random_start',dict(accept=Q.i,tooltip='number of MLE repeats from randomly chosen initialisation'),Q.Cbase.LinScalar(vtype=int,vmin=1,vmax=10)),
             ),
            ('clevel',dict(accept=Q.i,tooltip='Confidence level'),Q.Cbase.LinScalar(vtype=float,vmin=.9,vmax=.9999)),
            ('gpmean',dict(accept=Q.i,sel=None,tooltip='Check to show GP mean (linear combination of basis functions)'),Q.Cbase.Boolean(),),
            ('nsample',dict(accept=Q.i,tooltip='Number of test samples'),Q.Cbase.LinScalar(vtype=int,vmin=50,vmax=500)),
            ('logscale',dict(accept=Q.i,sel=None,tooltip='Check for x-axis in logscale'),Q.Cbase.Boolean(),),
            )
    launchui(config,width=800)
Exemplo n.º 3
0
def runui():
#--------------------------------------------------------------------------------------------------
    from animate import launchui
    def config(*animate):
        from animate import cfg_anim
        from myutil import quickui
        ffmt = '{:.1f}'.format
        Q = quickui.cbook
        return quickui.configuration(
            Q.Ctransf(
              partial(
                dict,
                srate=25.,
                taild=1.,
                maxtime=infty,
                ),
              multi=True,
              ),
            ('srate',dict(sel=None,accept=Q.i,tooltip='sample rate in Hz'),
             Q.Cbase.LinScalar(vmin=10,vmax=50,nval=1000,vtype=float,fmt=ffmt)
             ),
            ('taild',dict(sel=None,accept=Q.i,tooltip='shadow length in s'),
             Q.Cbase.LinScalar(step=1,vmin=0,vmax=10,vtype=float,fmt=ffmt)
             ),
            ('syst',dict(sel=None),
             Q.Ctransf(
                partial(
                  Pendulum,
                  L=1.,
                  G=9.81,
                  )
                ),
             ('G',dict(accept=Q.i,tooltip='gravity acceleration in m/s^2'),
              Q.Cbase.LinScalar(vmin=1.,vmax=20.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ('L',dict(accept=Q.i,tooltip='length of pendulum in m'),
              Q.Cbase.LinScalar(vmin=.1,vmax=10.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ),
            ('ini',dict(),
             Q.Ctransf(
                partial(
                    Pendulum.makestate,
                    theta=179.,
                    )
                  ),
              ('theta',dict(accept=Q.i,tooltip='initial angle of pendulum in deg'),
               Q.Cbase.LinScalar(vmin=-180.,vmax=180.,nval=1000,vtype=float,fmt=ffmt)
               ),
              ),
            ('maxtime',dict(accept=Q.i,tooltip='duration of simulation in s'),
              Q.Cbase.LinScalar(step=1.,vmin=10.,vmax=3600.,vtype=float,fmt=ffmt)
              ),
            ('animate',dict(sel=False))+
            cfg_anim(
              *animate,
               modifier=dict(
                timer=dict(
                  interval=40.,
                  ),
                save=dict(
                  filename='pendulum1.mp4',
                  metadata=dict(
                    title='A simple pendulum simulation',
                    ),
                  ),
                )
               ),
            )
    launchui(config,width=600)
Exemplo n.º 4
0
def runui():
#--------------------------------------------------------------------------------------------------
    from animate import launchui
    def config(*animate):
        from animate import cfg_anim
        from myutil import quickui
        krange = range(1,4)
        ffmt = '{0:.2f}'.format
        Q = quickui.cbook
        def normalise(a): return a/sum(a)
        def c_component():
            return (
                Q.Ctransf(
                    partial(
                        bvn,
                        mx=10*rand(),
                        my=10*rand(),
                        vx=10*rand(),
                        vy=10*rand(),
                        cor=rand(),
                        )
                    ),
                ('mx',dict(accept=Q.i),
                    Q.Cbase.LinScalar(vmin=0.,vmax=10.,nval=100,vtype=float,fmt=ffmt)
                    ),
                ('my',dict(accept=Q.i),
                    Q.Cbase.LinScalar(vmin=0.,vmax=10.,nval=100,vtype=float,fmt=ffmt)
                    ),
                ('vx',dict(accept=Q.i),
                    Q.Cbase.LinScalar(vmin=0.,vmax=10.,nval=100,vtype=float,fmt=ffmt)
                    ),
                ('vy',dict(accept=Q.i),
                    Q.Cbase.LinScalar(vmin=0.,vmax=10.,nval=100,vtype=float,fmt=ffmt)
                    ),
                ('cor',dict(accept=Q.i),
                    Q.Cbase.LinScalar(vmin=-1.,vmax=1.,nval=100,vtype=float,fmt=ffmt)
                    ),
                )
        def c_weight():
            return (
                Q.Cbase.LinScalar(vmin=0.,vmax=10.,nval=100,vtype=float,fmt=ffmt),
                )
        return quickui.configuration(
            Q.Ctransf(dict,multi=True),
            ('syst',dict(sel=None),
             Q.Ctransf(
                partial(
                  Kmeans,
                  K=5,
                  )
                ),
             ('data',dict(sel=None),
              Q.Ctransf(
                  partial(
                    mixture,
                    N=1000,
                    )
                  ),
              ('N',dict(accept=Q.i,tooltip='Number of points'),
               Q.Cbase.LinScalar(vmin=50,vmax=20000,nval=1000,vtype=int)
               ),
              ('weights',dict(tooltip='Weights of the generating mixture'),
               Q.Ccomp(lambda l: normalise(array(Q.selectv(l))),
                       defaultdict(lambda: 10*uniform())
                       )
               )+tuple(('w'+str(k),dict(accept=Q.i))+c_weight() for k in krange),
              ('comp',dict(tooltip='Components of the generating mixture'),
               Q.Ccomp(Q.selectv,None)
               )+tuple(('c'+str(k),dict(anchor=True))+c_component() for k in krange),
              ),
             ('K',dict(accept=Q.i,tooltip='Number of clusters'),
              Q.Cbase.LinScalar(vmin=2,vmax=20,step=1,vtype=int)
              ),
             ),
            ('animate',dict(sel=False))+
            cfg_anim(
              *animate,
               modifier=dict(
                save=dict(
                  filename='kmeans.mp4',
                  metadata=dict(
                    title='An execution of the kmeans algorithm',
                    ),
                  ),
                )
               ),
            )
    launchui(config,width=800)
Exemplo n.º 5
0
def runui():
    from animate import launchui
    def test(*animate):
        from animate import cfg_anim
        from myutil import quickui
        ffmt = '{:.1f}'.format
        Q = quickui.cbook
        return quickui.configuration(
            Q.Ctransf(
              partial(
                dict,
                srate=25.,
                taild=1.,
                maxtime=infty,
                ),
              multi=True,
              ),
            ('srate',dict(sel=None,accept=Q.i,tooltip='sample rate in Hz'),
             Q.Cbase.LinScalar(vmin=10,vmax=50,nval=1000,vtype=float,fmt=ffmt)
             ),
            ('taild',dict(sel=None,accept=Q.i,tooltip='shadow length in s'),
             Q.Cbase.LinScalar(step=1,vmin=0,vmax=10,vtype=float)
             ),
            ('syst',dict(sel=None),
             Q.Ctransf(
                partial(
                  DoublePendulum,
                  M1=5.,
                  L1=2.,
                  M2=.1,
                  L2=1.,
                  G=9.81,
                  )
                ),
             ('G',dict(accept=Q.i,tooltip='acceleration due to gravity in m/s^2'),
              Q.Cbase.LinScalar(vmin=1.,vmax=20.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ('M1',dict(accept=Q.i,tooltip='mass of pendulum 1 in kg'),
              Q.Cbase.LinScalar(vmin=.05,vmax=20.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ('L1',dict(accept=Q.i,tooltip='length of pendulum 1 in m'),
              Q.Cbase.LinScalar(vmin=.1,vmax=10.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ('M2',dict(accept=Q.i,tooltip='mass of pendulum 2 in kg'),
              Q.Cbase.LinScalar(vmin=.05,vmax=20.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ('L2',dict(accept=Q.i,tooltip='length of pendulum 2 in m'),
              Q.Cbase.LinScalar(vmin=.1,vmax=10.,nval=1000,vtype=float,fmt=ffmt)
              ),
             ),
            ('ini',dict(),
              Q.Ctransf(
                  partial(
                    DoublePendulum.makestate,
                    theta1=180.,
                    theta2=1., 
                    )
                  ),
              ('theta1',dict(accept=Q.i,tooltip='initial angle of pendulum 1 in deg'),
               Q.Cbase.LinScalar(vmin=-180.,vmax=180.,nval=1000,vtype=float,fmt=ffmt)
               ),
              ('theta2',dict(accept=Q.i,tooltip='initial angle of pendulum 2 in deg'),
               Q.Cbase.LinScalar(vmin=-180.,vmax=180.,nval=1000,vtype=float,fmt=ffmt)
               ),
              ),
            ('maxtime',dict(accept=Q.i,tooltip='duration of simulation in s'),
              Q.Cbase.LinScalar(step=1.,vmin=10.,vmax=3600.,vtype=float,fmt=ffmt)
              ),
            ('animate',dict(sel=False))+
            cfg_anim(
              *animate,
               modifier=dict(
                timer=dict(
                  interval=40.,
                  ),
                save=dict(
                  filename='pendulum2.mp4',
                  extra_args = ('-cache','1000000'),
                  metadata=dict(
                    title='A double pendulum simulation',
                    ),
                  ),
                )
               ),
            )
    launchui(test,width=600)