How to use the orange.SymMatrix function in Orange

To help you get started, we’ve selected a few Orange examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github biolab / orange2 / Orange / OrangeWidgets / Unsupervised / OWDistanceFile.py View on Github external
fle = fn
        else:
            fle = open(fn)
        while 1:
            lne = fle.readline().strip()
            if lne:
                break
        spl = lne.split()
        try:
            dim = int(spl[0])
        except IndexError:
            raise ValueError("Matrix dimension expected in the first line.")
        
        #print dim
        labeled = len(spl) > 1 and spl[1] in ["labelled", "labeled"]
        matrix = orange.SymMatrix(dim)
        data = None
        
        milestones = orngMisc.progressBarMilestones(dim, 100)     
        if labeled:
            labels = []
        else:
            labels = [""] * dim
        for li, lne in enumerate(fle):
            if li > dim:
                if not li.strip():
                    continue
                raise ValueError("File to long")
            
            spl = lne.split("\t")
            if labeled:
                labels.append(spl[0].strip())
github biolab / orange2 / orange / OrangeWidgets / Associate / OWDistanceFile.py View on Github external
pkl_file.close()
            else:    
                fle = open(fn)
                while 1:
                    lne = fle.readline().strip()
                    if lne:
                        break
                spl = lne.split()
                try:
                    dim = int(spl[0])
                except:
                    msg = "Matrix dimension expected in the first line"
                    raise exceptions.Exception
            
                labeled = len(spl) > 1 and spl[1] in ["labelled", "labeled"]
                self.matrix = matrix = orange.SymMatrix(dim)
                if labeled:
                    self.labels = []
                else:
                    self.labels = [""] * dim
                for li, lne in enumerate(fle):
                    if li > dim:
                        if not li.strip():
                            continue
                        msg = "File too long"
                        raise exceptions.IndexError
                    spl = lne.split("\t")
                    if labeled:
                        self.labels.append(spl[0].strip())
                        spl = spl[1:]
                    if len(spl) > dim:
                        msg = "Line %i too long" % li+2
github biolab / orange2 / orange / orng / orngVizRank.py View on Github external
def evaluateProjection(self, data):
        if self.graph.data_has_discrete_class:
            return self.kNNComputeAccuracy(data)
        elif self.graph.data_has_continuous_class:
            return 0
        else:
            matrix = orange.SymMatrix(len(data))
            matrix.setattr('items', data)
            dist = orange.ExamplesDistanceConstructor_Euclidean(data)
            for i in range(len(data)):
                for j in range(i+1):
                    matrix[i, j] = dist(data[i], data[j])
            root = orange.HierarchicalClustering(matrix, linkage = orange.HierarchicalClustering.Ward, overwriteMatrix = 0)
            val = self.computeTotalHeight(root)
            return val, (val)
github biolab / orange2 / orange / OrangeWidgets / Associate / OWDistanceMap.py View on Github external
def distanceMatrix(data):
        dist = orange.ExamplesDistanceConstructor_Euclidean(data)
        matrix = orange.SymMatrix(len(data))
        matrix.setattr('items', data)
        for i in range(len(data)):
            for j in range(i+1):
                matrix[i, j] = dist(data[i], data[j])
        return matrix
github biolab / orange2 / orange / doc / reference / hclust.py View on Github external
import orange, time

def repTime(msg):
    #print "%s: %s" % (time.asctime(), msg)
    pass

def callback(f, o):
    print int(round(100*f)),
    
repTime("Loading data")    
data = orange.ExampleTable("iris")

repTime("Computing distances")
matrix = orange.SymMatrix(len(data))
matrix.setattr("objects", data)
distance = orange.ExamplesDistanceConstructor_Euclidean(data)
for i1, ex1 in enumerate(data):
    for i2 in range(i1+1, len(data)):
        matrix[i1, i2] = distance(ex1, data[i2])

repTime("Hierarchical clustering (single linkage)")
clustering = orange.HierarchicalClustering()
clustering.linkage = clustering.Average
clustering.overwriteMatrix = 1
root = clustering(matrix)

repTime("Done.")

def prune(cluster, togo):
    if cluster.branches:
github biolab / orange2 / orange / doc / modules / mds1.py View on Github external
import orange, orngMDS, math

data=orange.ExampleTable("../datasets/iris.tab")
dist = orange.ExamplesDistanceConstructor_Euclidean(data)
matrix = orange.SymMatrix(len(data))
for i in range(len(data)):
   for j in range(i+1):
       matrix[i, j] = dist(data[i], data[j])

mds=orngMDS.MDS(matrix)
#mds.Torgerson()
mds.getStress(orngMDS.KruskalStress)

i=0
while 100>i:
    i+=1
    oldStress=mds.avgStress
    for j in range(10): mds.SMACOFstep()
    mds.getStress(orngMDS.KruskalStress)
    if oldStress*1e-3 > math.fabs(oldStress-mds.avgStress):
        break;
github biolab / orange2 / orange / doc / reference / symmatrix.py View on Github external
import orange

m = orange.SymMatrix(4)
for i in range(4):
    for j in range(i+1):
        m[i, j] = (i+1)*(j+1)


print m
print

m.matrixType = m.Upper
print m
print

m.matrixType = m.UpperFilled
print m
print
github biolab / orange2 / orange / OrangeWidgets / Associate / OWExampleDistance.py View on Github external
def computeMatrix(self):
        if not self.data:
            return
        data = self.data
        dist = self.metrics[self.Metrics][1](data)
        self.matrix = orange.SymMatrix(len(data))
        self.matrix.setattr('items', data)
        for i in range(len(data)):
            for j in range(i+1):
                self.matrix[i, j] = dist(data[i], data[j])
        self.send("Distance Matrix", self.matrix)