Commit 3ac184a8 authored by tpetaja1's avatar tpetaja1
Browse files

fixes to files, results

parent 47bd7a3e
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -93,9 +93,9 @@ class DataHandler(object):

    def write_results(self, datafile, alg_type, alg):
        run_time = datetime.datetime.now()
        results_name = "results/%s_d%sb%so%s_%s.txt" % (
            alg_type, alg.dimension, alg.blocks, alg.obs,
            run_time.strftime("%Y%m%d%H%M%S"))
        results_name = "results/%s_di%sbl%sob%sla%sbe%s_%s.txt" % (
            alg_type, alg.dimension, alg.blocks, alg.obs, alg.lambd,
            alg.beta, run_time.strftime("%Y%m%d%H%M%S"))
        with open(results_name, "w") as f:
            f.write("# Information\n")
            f.write("Run datetime: %s\n" %
@@ -108,12 +108,18 @@ class DataHandler(object):
            f.write("Rho: %s\n" % alg.rho)
            f.write("Beta: %s\n" % alg.beta)
            f.write("Lambda: %s\n" % alg.lambd)
            f.write("Processes used: %s\n\n" % alg.processes)
            f.write("Processes used: %s\n" % alg.processes)
            f.write("Total edges: %s\n" % alg.real_edges)
            f.write("Total edgeless: %s\n\n" % alg.real_edgeless)
            f.write("# Results\n")
            f.write("Algorithm run time: %s seconds\n" % alg.run_time)
            f.write("Iterations to complete: %s\n\n" % alg.iteration)
            f.write("Matching edge ratio (nonzeros): {0:.3f}\n"
                    .format(alg.nonzero_ratio))
            f.write("Matching edge ratio: {0:.3f}"
                    .format(alg.matching_edges_ratio))
            f.write("    (Matching edges: %s)\n" % alg.matching_edges)
            f.write("False edge ratio: {0:.3f}"
                    .format(alg.false_edges_ratio))
            f.write("    (False edges: %s)\n" % alg.false_edges)
            f.write("Temporal deviations ratio (max/mean): {0:.3f}\n"
                    .format(alg.dev_ratio))
            f.write("Temporal deviations: ")
+10 −7
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import multiprocessing
import time
import traceback

MAX_ITER = 5000
MAX_ITER = 10000


def mp_parallel_tvgl((thetas, z0s, z1s, z2s, u0s, u1s, u2s,
@@ -76,17 +76,20 @@ def mp_parallel_tvgl((thetas, z0s, z1s, z2s, u0s, u1s, u2s,
                for i in range(nn):
                    dif = thetas[i] - thetas_pre[i]
                    fro_norm += np.linalg.norm(dif)
                if fro_norm < 1e-5:
                if fro_norm < 1e-4:
                    stopping_criteria[proc_index] = True
            if all(criteria is True for criteria in stopping_criteria):
                break
            thetas_pre = list(thetas)
            iteration += 1
            if iteration % 500 == 0 and proc_index == 0:
                print "*** Iteration: %s ***\n" % iteration
        if next_pipe is not None:
            next_pipe.send(None)
        if prev_pipe is not None:
            prev_pipe.send(None)
                break
            thetas_pre = list(thetas)
            iteration += 1
        out_queue.put((final_thetas, iteration))
        print "Process %s finished" % proc_index
    except Exception as e:
        traceback.print_exc()
        raise e
@@ -102,7 +105,7 @@ class ParallelTVGL(TVGL):
        if self.processes > self.blocks:
            self.processes = self.blocks
        self.chunk = int(np.round(self.blocks/float(self.processes)))
        self.iteration = "n/a"
        print "Processes: %s" % self.processes

    def init_algorithm(self):
        self.results = multiprocessing.JoinableQueue()
+16 −11
Original line number Diff line number Diff line
@@ -179,18 +179,23 @@ class TVGL(object):
        self.dev_ratio = float(max(deviations))/float(np.mean(deviations))
        print "Temp deviations ratio: {0:.3g}".format(self.dev_ratio)

    def correct_nonzero_elements(self):
        self.real_nonzeros = 0
        self.matching_nonzeros = 0
    def correct_edges(self):
        self.real_edges = 0
        self.real_edgeless = 0
        self.matching_edges = 0
        self.false_edges = 0
        for real_network, network in zip(self.real_thetas, self.thetas):
            for i in range(self.dimension):
                for j in range(self.dimension):
            for i in range(self.dimension - 1):
                for j in range(i + 1, self.dimension):
                    if real_network[i, j] != 0:
                        self.real_nonzeros += 1
                        self.real_edges += 1
                        if network[i, j] != 0:
                            self.matching_nonzeros += 1
                            self.matching_edges += 1
                    elif real_network[i, j] == 0:
                        if network[i, j] == 0:
                            self.matching_nonzeros += 1
        self.nonzero_ratio = float(self.matching_nonzeros)/float(
            self.dimension*self.dimension*self.blocks)
                        self.real_edgeless += 1
                        if network[i, j] != 0:
                            self.false_edges += 1
        self.matching_edges_ratio = float(self.matching_edges)/float(
            self.real_edges)
        self.false_edges_ratio = float(self.false_edges)/float(
            self.real_edgeless)
+0 −17
Original line number Diff line number Diff line
# Information
Run datetime: 2017-08-08 23:27:20
Data file: synthetic_data/1000x20_20170808191313.csv
Algorithm type: multi
Data dimension: 20
Blocks: 20
Observations in a block: 50
Rho: 50
Beta: 4
Lambda: 90
Processes used: 20

# Results
Algorithm run time: 253 seconds
Iterations to complete: 637

Temporal deviations: 0.488 0.445 0.449 0.414 0.418 0.392 0.416 0.424 0.411 1.000 0.388 0.404 0.368 0.345 0.378 0.399 0.393 0.403 0.468 
+0 −19
Original line number Diff line number Diff line
# Information
Run datetime: 2017-09-04 23:55:54
Data file: synthetic_data/1000x20_20170823203622.csv
Algorithm type: parallel
Data dimension: 20
Blocks: 50
Observations in a block: 20
Rho: 6.7
Beta: 50
Lambda: 40
Processes used: 25

# Results
Algorithm run time: 19 seconds
Iterations to complete: 2741

Matching edge ratio (nonzeros): 0.356
Temporal deviations ratio (max/mean): 28.885
Temporal deviations: 0.001 0.001 0.000 0.003 0.042 0.000 0.023 0.000 0.001 0.001 0.009 0.002 0.002 0.001 0.001 0.010 0.001 0.017 0.001 0.001 0.015 0.000 0.084 0.013 1.000 0.002 0.015 0.002 0.002 0.002 0.041 0.082 0.034 0.019 0.007 0.022 0.010 0.033 0.002 0.030 0.049 0.004 0.004 0.013 0.022 0.056 0.003 0.013 0.004 
Loading