def SNF_reduction(self): while True: self._computedSNF = False self.computeSNF() all_diag = True for p in self.dimensions: T = np.zeros_like(self.D[p]) T[:min(self.D[p].shape), :min(self.D[p].shape)] = np.diag(np.diag(self.D[p])) all_diag = all_diag and np.all(T == self.D[p]) if not all_diag: continue if all_diag: break f_A = ChainMap(self, matrices={q: self.A[q].T for q in self.dimensions}) f_G = ChainMap(self, matrices={q: self.G[q].T for q in self.dimensions}) f_D = ChainMap(self, matrices={q: self.D[q].T for q in self.dimensions}, degree=self._degree) M = ChainComplex(cell_class=self.cell_class) M._degree = +1 for q in self.dimensions: M[q] = self[q] M.d = f_D return Reduction( src=self, dst=M, projection=f_G, inclusion=f_A, integral=ChainMap(self, degree=-self._degree) )
def fit(self, stable_antecedents: List[str], flexible_antecedents: List[str], consequent: str, conf: float, supp: float, desired_classes: List[str] = None, desired_changes: List[list] = None, is_nan: bool = False, is_reduction: bool = True, min_stable_antecedents: int = 1, min_flexible_antecedents: int = 1): """ Get action rules. Define antecedent and consequent. - stable_antecedents - List of column names. - flexible_antecedents - List of column names. - consequent - Name of column. Confidence and support. - conf - value in % for confidence of classification rules. - supp - value in % for support of classification rules. Desired classes or desired changes must be entered. - desired_classes - List of decision states. For example ["1"]. DEFAULT: None - desired_changes - List of desired changes. For example [["0", "1"]]. DEFAULT: None Should nan values be used. - is_nan - True means nan values are used, False means nan values are not used. DEFAULT: FALSE Should the reduction table be used. - is_reduction - is reduction table used DEFAULT: TRUE Minimal number of stable and flexible couples - min_stable_antecedents - min. stable couples. DEFAULT: 1 - min_flexible_antecedents - min. flexible couples. DEFAULT: 1 """ if bool(desired_classes) != bool(desired_changes): desired_state = DesiredState(desired_classes=desired_classes, desired_changes=desired_changes) else: raise Exception( "Desired classes or desired changes must be entered") antecedents = stable_antecedents + flexible_antecedents self.decisions.prepare_data_fim(antecedents, consequent) self.decisions.fit_fim_apriori(conf=conf, support=supp) self.decisions.generate_decision_table() stable = self.decisions.decision_table[stable_antecedents] flex = self.decisions.decision_table[flexible_antecedents] target = self.decisions.decision_table[[consequent]] supp = self.decisions.support conf = self.decisions.confidence reduced_tables = Reduction(stable, flex, target, desired_state, supp, conf, is_nan) if is_reduction: reduced_tables.reduce() action_rules = ActionRules( reduced_tables.stable_tables, reduced_tables.flexible_tables, reduced_tables.decision_tables, desired_state, reduced_tables.supp, reduced_tables.conf, is_nan, min_stable_antecedents, min_flexible_antecedents) action_rules.fit() self.action_rules = action_rules.action_rules
def reduction(self): cplx = self.decomposition() d = self.src.d pi_t, pi_s, pi_c, iota_t, iota_s, iota_c = self._projections_inclusions(cplx) d_33 = pi_c * d * iota_c d_31 = pi_c * d * iota_t d_21 = pi_s * d * iota_t d_21_inv = ChainMap(d_21.dst, d_21.src, degree=+1) for p in self.dimensions: d_21_inv[p] = np.linalg.inv(d_21[p + 1]).astype(np.int32) d_23 = pi_s * d * iota_c cplx['c'].d = d_33 - d_31 * d_21_inv * d_23 f = pi_c - d_31 * d_21_inv * pi_s g = iota_c - iota_t * d_21_inv * d_23 h = iota_t * d_21_inv * pi_s return Reduction(self.src, cplx['c'], f, g, h)
def __reduction(self): reductor = Reduction(self.__population, self.population_size, self.x_min, self.x_max) reductor.perform()
def am_model(self, do_SNF=True, verbose=False): st = time() pt = time() reduction = self.reduction() if verbose: print('Vector field reduction calculated in {:.3f}s'.format(time() - pt)) pt = time() V = create_vector_field(reduction.dst) if verbose: print('Reduced vector field built in {:.3f}s'.format(time() - pt)) while V != 0: pt = time() reduction = V.reduction() * reduction if verbose: print('Vector field reduction calculated in {:.3f}s'.format(time() - pt)) pt =time() V = create_vector_field(reduction.dst) if verbose: print('Reduced vector field built in {:.3f}s'.format(time() - pt)) if do_SNF: # Compute SNF if necessary if reduction.dst.d != 0: pt = time() snf_reduction = reduction.dst.SNF_reduction() if verbose: print('SNF reduction calculated in {:.3f}s'.format(time() - pt)) pt = time() reduction = snf_reduction * reduction if verbose: print('Final reduction built in {:.3f}s'.format(time() - pt)) # Make all differentials have positive coefficient pt = time() f_sign = ChainMap(reduction.dst) h_sign = ChainMap(reduction.dst, degree=1) for sigma in reduction.dst: co_d = reduction.dst.d.T c = co_d(sigma) if c: tau = next(iter(c)) if c[tau] < 0: f_sign.set_image(sigma, -sigma) else: f_sign.set_image(sigma, sigma) else: f_sign.set_image(sigma, sigma) new_dst = ChainComplex(cell_class=reduction.dst.cell_class) for p in reduction.dst.dimensions: new_dst[p] = reduction.dst[p] new_d = ChainMap(new_dst, degree=-1) for p, M in reduction.dst.d.matrices.items(): new_d[p] = np.abs(M) new_dst.d = new_d reduction = Reduction(reduction.dst, new_dst, f_sign, f_sign, h_sign) * reduction if verbose: print('Signs adjusted in {:.3f}s'.format(time() - pt)) print('Full time {:.3f}s'.format(time() - pt)) return reduction
def getSummary(): #actually calculate summary opLabel.pack() opEntry.pack() opEntry.config(state='normal' , bg="white" , fg="black") opEntry.delete(1.0,END) opEntry.insert(INSERT,"Generating Summary...") global endTime1,endTime2 startTime = time.time() text = ipEntry.get("1.0", END) ps = PorterStemmer() red_ra=redRatio.get()/100.00 if var1.get(): words = text.split() for w in words: text += ps.stem(w) text += " " if var6.get()==1: r = Reduction() #object of class Red.. reduced_text = r.reduce(text, red_ra) op=' '.join(reduced_text) global opTA opTA=op elif var6.get()==2: m = modelVC.summary() op = m.summarize(text,red_ra) global opPA opPA=op if var2.get()==1: op=shortForm.shortF(op) opEntry.delete(1.0,END) opEntry.insert(INSERT, op) if var6.get()==1: endTime1 = time.time() - startTime print("Time taken: %f secs" %endTime1) if var4.get(): tkMessageBox.showinfo("Statistics", "Time taken to complete: %f secs" %endTime) if var6.get()==2: endTime2 = time.time() - startTime print("Time taken: %f secs" %endTime2) if var4.get(): tkMessageBox.showinfo("Statistics", "Time taken to complete: %f secs" %endTime) if var3.get() == 1: file_f = open("log.txt", "a") lenText=len(text) file_f.write("\nInput length: %d" %lenText) lenText = len(op) file_f.write("\tSummary length: %d" % lenText) file_f.write('\nStemming: %d' %var1.get()) file_f.write('\tShort Forms: %d' %var2.get()) file_f.write('\tReduction Ratio: %d percent' % redRatio.get()) file_f.write('\tModel: %d ' % var6.get()) if var6.get()==1: file_f.write("\nTime taken: %f secs\n" %endTime1) if var6.get()==2: file_f.write("\nTime taken: %f secs\n" %endTime2) file_f.close()