def marginal(self, X, N):
     if not isinstance(X, types.ListType):
         X = [X]
     Nx = [DiscreteDistribution(x) for x in X]
     queryIndex = array([x.index for x in X])
     state = copy.copy(self.evidence)
     nonEvidence = state.empty()
     randMax = array([node.size() for node in nonEvidence])
     #ASSUMPTION: zero is the minimum value
     randMin = zeros([len(nonEvidence)])
     #initialize nonEvidence variables to random values
     state[nonEvidence] = ra.randint(randMin, randMax)
     for i in range(N):
         #record the value of all of the query variables
         # We start with a 100 sample cut as default
         if i > 100:
             for (node, dist) in zip(X, Nx):
                 index = dist.generate_index([state[node]],
                                             range(dist.nDims))
                 dist[index] += 1
                 for node in nonEvidence:
                     val = self.sample_value_given_mb(node, state)
                     #change the state to reflect new value of given variable
                     if not state[node] == val:
                         state[node] = val
     for dist in Nx:
         dist.normalize()
     return Nx
Пример #2
0
def randomData(mb):
    'Generate mb megabytes of random data'
    ## will create array with 4 byte integers
    n = 1024 * 1024 * mb / 2
    a = rand.randint(-2147483648, 2147483648, n)
    a = num.asarray(a, uint16)
    return a
Пример #3
0
def randomData(mb):
	'Generate mb megabytes of random data'
	## will create array with 4 byte integers
	n = 1024 * 1024 * mb / 2
	a = rand.randint(-2147483648, 2147483648, n)
	a = num.asarray(a, uint16)
	return a
Пример #4
0
 def marginal (self, X, N):
     if not isinstance(X, types.ListType):
         X = [X]
     Nx = [DiscreteDistribution(x) for x in X]
     queryIndex = array([x.index for x in X])
     state = copy.copy(self.evidence)
     nonEvidence = state.empty()
     randMax = array([node.size() for node in nonEvidence])
     #ASSUMPTION: zero is the minimum value
     randMin = zeros([len(nonEvidence)])
     #initialize nonEvidence variables to random values
     state[nonEvidence] = ra.randint(randMin, randMax)
     for i in range(N):
         #record the value of all of the query variables
         # We start with a 100 sample cut as default
         if i > 100:
             for (node, dist) in zip(X, Nx):
                 index = dist.generate_index([state[node]], range(dist.nDims))
                 dist[index] += 1
                 for node in nonEvidence:
                     val = self.sample_value_given_mb(node, state)
                     #change the state to reflect new value of given variable
                     if not state[node] == val:
                         state[node] = val             
     for dist in Nx:
         dist.normalize()
     return Nx
Пример #5
0
def timeRandomCorrect(n, size):
    s = size * size
    a = rand.randint(0, 2**16, s)
    a = num.array(a, uint16)
    d = rand.random(s)
    d = num.array(d, float64)
    b = rand.random(s)
    b = num.array(b, float64)
    timefunc(n, correct, (a, d, b))
Пример #6
0
def timeRandomCorrect(n, size):
	s = size*size
	a = rand.randint(0,2**16, s)
	a = num.array(a, uint16)
	d = rand.random(s)
	d = num.array(d, float64)
	b = rand.random(s)
	b = num.array(b, float64)
	timefunc(n, correct, (a,d,b))
Пример #7
0
"""#3216"""

import numarray as na
import numarray.random_array as nar
IM16 = nar.randint(0, 256, 300).astype(na.UInt8)
Пример #8
0
def randomImage(dim):
    n = dim * dim
    a = rand.randint(-2147483648, 2147483648, n)
    a = num.asarray(a, uint16)
    a.shape = dim, dim
    return a
Пример #9
0
    def run(self,n_sources = 3, n_observations = 21, ra_range = [-20.0,20.0],dec_range=[-20.0,20.0],typical_err=0.3,reuse=True):
    
        global real_list
 
        clf()
        # make the real sources
        if reuse:
            try:
                type(real_list) == type([])
            except NameError:
                reuse = False
                real_list = []

        for ns in range(n_sources):
            if not reuse:
                real_list.append(source(start_pos=[random_array.uniform(ra_range[0],ra_range[1]),random_array.uniform(dec_range[0],dec_range[1])],
                    stype='real',start_err=[0.0,0.0],associated_obs=[]))
                # print real_list[-1]
            real_list[ns].plot()
    
        
        constructed_source_list = []
        observation_list = []
    
        ## pick a vector of len n_obsevations sources to choose from from 0 --> n_source - 1
        s_start_ind = random_array.randint(0,n_sources,shape=[n_observations])
        for i in range(n_observations):
            # choose a real source to draw an observation from
            o = obs(initial_pos=real_list[s_start_ind[i]].start_pos,true_err=[[typical_err**2,0.0],[0.0,typical_err**2]],assumed_err=[1.1*typical_err,1.1*typical_err])
            o.observe_pos()
            o.plot()
            tmp = o.is_associated_with_source(constructed_source_list)
            # print tmp
            if tmp['answer'] == True:
                # o.associate_with_source(tmp['sources'])
                for s in tmp['best_source']:
                    # print (len(tmp['best_source']),o.pos,s.current_pos)
                    s.add_associated_obs(copy.deepcopy(o))
                    s.recalculate_position()
            else:
                ## make a new source
                s = source(start_pos=copy.copy(o.pos),stype='constructed',start_err=copy.copy(o.assumed_err),current_pos=copy.copy(o.pos),\
                    current_err=copy.copy(o.assumed_err),associated_obs=[copy.deepcopy(o)])
                print "new source"
                #print s
                #print s.associated_obs
                constructed_source_list.append(copy.deepcopy(s))

            observation_list.append(copy.deepcopy(o))
    
        for s in constructed_source_list:
            # print s
            s.plot('g^')
        
        ## do the comparisons between real and constructed sources
        for ns in range(n_sources):
            #real_list[ns].plot('ys')
            pass
        
        self.real_list = real_list
        self.constructed_source_list = constructed_source_list
        self.real_pos  = (numarray.fromlist([x.start_pos for x in self.real_list]))
        self.constructed_pos  = (numarray.fromlist([x.current_pos for x in self.constructed_source_list]))
Пример #10
0
def randomImage(dim):
	n = dim * dim
	a = rand.randint(-2147483648, 2147483648, n)
	a = num.asarray(a, uint16)
	a.shape = dim,dim
	return a
Пример #11
0
    def run(self,
            n_sources=3,
            n_observations=21,
            ra_range=[-20.0, 20.0],
            dec_range=[-20.0, 20.0],
            typical_err=0.3,
            reuse=True):

        global real_list

        clf()
        # make the real sources
        if reuse:
            try:
                type(real_list) == type([])
            except NameError:
                reuse = False
                real_list = []

        for ns in range(n_sources):
            if not reuse:
                real_list.append(
                    source(start_pos=[
                        random_array.uniform(ra_range[0], ra_range[1]),
                        random_array.uniform(dec_range[0], dec_range[1])
                    ],
                           stype='real',
                           start_err=[0.0, 0.0],
                           associated_obs=[]))
                # print real_list[-1]
            real_list[ns].plot()

        constructed_source_list = []
        observation_list = []

        ## pick a vector of len n_obsevations sources to choose from from 0 --> n_source - 1
        s_start_ind = random_array.randint(0,
                                           n_sources,
                                           shape=[n_observations])
        for i in range(n_observations):
            # choose a real source to draw an observation from
            o = obs(initial_pos=real_list[s_start_ind[i]].start_pos,
                    true_err=[[typical_err**2, 0.0], [0.0, typical_err**2]],
                    assumed_err=[1.1 * typical_err, 1.1 * typical_err])
            o.observe_pos()
            o.plot()
            tmp = o.is_associated_with_source(constructed_source_list)
            # print tmp
            if tmp['answer'] == True:
                # o.associate_with_source(tmp['sources'])
                for s in tmp['best_source']:
                    # print (len(tmp['best_source']),o.pos,s.current_pos)
                    s.add_associated_obs(copy.deepcopy(o))
                    s.recalculate_position()
            else:
                ## make a new source
                s = source(start_pos=copy.copy(o.pos),stype='constructed',start_err=copy.copy(o.assumed_err),current_pos=copy.copy(o.pos),\
                    current_err=copy.copy(o.assumed_err),associated_obs=[copy.deepcopy(o)])
                print "new source"
                #print s
                #print s.associated_obs
                constructed_source_list.append(copy.deepcopy(s))

            observation_list.append(copy.deepcopy(o))

        for s in constructed_source_list:
            # print s
            s.plot('g^')

        ## do the comparisons between real and constructed sources
        for ns in range(n_sources):
            #real_list[ns].plot('ys')
            pass

        self.real_list = real_list
        self.constructed_source_list = constructed_source_list
        self.real_pos = (numarray.fromlist(
            [x.start_pos for x in self.real_list]))
        self.constructed_pos = (numarray.fromlist(
            [x.current_pos for x in self.constructed_source_list]))
Пример #12
0
#!/usr/bin/env python2.4

import wx
import numarray
from numarray import random_array
import RandomArray # the Numeric version
import time


NumLinePoints = 5000
NumPointPoints = 5000

## Make some random data to draw things with.
MaxX  = 500
LinesPoints = random_array.randint(1, MaxX, (NumLinePoints,2) )
#PointsPoints = random_array.randint(1, MaxX, (NumPointPoints,2) )
PointsPoints = RandomArray.randint(1, MaxX, (NumPointPoints,2) ) # Numeric



class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "DrawLines Test",
                         wx.DefaultPosition,
                         size=(500,500),
                         style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)

        ## Set up the MenuBar
        MenuBar = wx.MenuBar()
        
        file_menu = wx.Menu()