def __init__(self): self.seed = 12345 # TODO: Where should this row generating function be? # Here, in the LazyTable or in the LazyRowInstance self.class_vars = OrderedDict() self.class_vars['class'] = lambda row_index: numpy.random.randint(2) self.attributes_continuous = OrderedDict() # TODO HACK for incremental learner. if False: self.attributes_continuous['X'] = lambda row_index: numpy.random.random() * 4.0 + 2.0 self.attributes_continuous['Y'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['k'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['l'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['m'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['n'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['o'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['p'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['q'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['r'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['s'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['t'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['u'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 #self.attributes_continuous['X'] = lambda row_index: numpy.random.random() * 4.0 + 2.0 #self.attributes_continuous['Y'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 #self.attributes_continuous['k'] = lambda row_index: numpy.random.random() * 1e-8 - 1e-9 #self.attributes_continuous['l'] = lambda row_index: numpy.random.random() * 1e-10 - 2e-11 #self.attributes_continuous['m'] = lambda row_index: numpy.random.random() * 1e-12 + 3e-13 #self.attributes_continuous['n'] = lambda row_index: numpy.random.random() * 1e22 #self.attributes_continuous['o'] = lambda row_index: numpy.random.random() * 1e20 #self.attributes_continuous['p'] = lambda row_index: numpy.random.random() * 1e18 #self.attributes_continuous['q'] = lambda row_index: numpy.random.random() * 1e16 #self.attributes_continuous['r'] = lambda row_index: numpy.random.random() * 1e14 #self.attributes_continuous['s'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 #self.attributes_continuous['t'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 #self.attributes_continuous['u'] = lambda row_index: numpy.random.random() * 8.0 + 10.0 self.attributes_continuous['a'] = lambda row_index: \ numpy.random.normal(loc=1.0, scale=2.0) \ if self.pull_cell(row_index, 'class') == 0 else \ numpy.random.normal(loc=5.0, scale=2.0) self.attributes_continuous['b'] = lambda row_index: \ numpy.random.normal(loc=-1.0, scale=1.0) \ if self.pull_cell(row_index, 'class') == 0 else \ numpy.random.normal(loc=1.0, scale=0.5) self.data = LazyTable.from_domain(domain = self.pull_domain()) self.data.widget_origin = self self.data.name = "GeneratedTest1" # Pull some data so non-lazy aware widgets are not confused. self.data.pull_region_of_interest() self.send("Data", self.data)
def we_have_a_new_table(self): # TODO: think of better name for this function. domain = self.pull_domain() self.old_region_of_interest = None #self.region_of_interest = None data = LazyTable.from_domain(domain=domain) data.widget_origin = self # Stop the pulling loop in our current data, if any. if isinstance(self.data, LazyTable): self.data.stop_pulling = True self.data = data self.send("Data", self.data) print("Orange Table send B")
def open_file(self, fn, preload_data=True): #def open_file(self, fn, preload_rows=False): self.error() self.warning() self.information() if not os.path.exists(fn): dirname, basename = os.path.split(fn) if os.path.exists(os.path.join(".", basename)): fn = os.path.join(".", basename) self.information("Loading '{}' from the current directory." .format(basename)) if fn == "(none)" or not 'fixed' in fn: self.send("Data", None) self.infoa.setText("No data loaded") self.infob.setText("") self.warnings.setText("") return self.loaded_file = fn domain = self.pull_header() self.infoa.setText( '{} instance(s), {} feature(s), {} meta attributes' .format(self.pull_length(), len(domain.attributes), len(domain.metas))) if isinstance(domain.class_var, ContinuousVariable): self.infob.setText('Regression; Numerical class.') elif isinstance(domain.class_var, DiscreteVariable): self.infob.setText('Classification; Discrete class with {} values.' .format(len(domain.class_var.values))) # TODO: better class_vars support ('data' is unknown at this stage). #elif data.domain.class_vars: # self.infob.setText('Multi-target; {} target variables.' # .format(len(data.domain.class_vars))) else: self.infob.setText("Data has no target variable.") # What does this do? #addOrigin(data, fn) # make new data and send it #data = LazyTable() #data.domain = domain # Creating the LazyTable from the domain will ensure that # X, Y and metas are set as well, to empty numpy arrays. data = LazyTable.from_domain(domain) data.widget_origin = self # The name is necessary for the scatterplot fName = os.path.split(fn)[1] if "." in fName: data.name = fName[:fName.rfind('.')] else: data.name = fName # What does this do? #self.dataReport = self.prepareDataReport(data) self.data = data # Ensure that some data is always available. if preload_data: self.pull_region_of_interest() else: self.send("Data", self.data)