コード例 #1
0
 def test_basic(self):
     tracer = VizTracer()
     tracer.start()
     counter = VizCounter(tracer, "name")
     counter.a = 1
     counter.b = 2
     tracer.stop()
     entries = tracer.parse()
     self.assertEqual(entries, 2)
コード例 #2
0
    def test_notracer(self):
        counter = VizCounter(None, "name")
        counter.a = 1
        counter.b = 2

        a = Hello(None, "name")
        a.b = 1
        a.c = 2
        a.d = 3
        a.log()
コード例 #3
0
 def test_exception(self):
     tracer = VizTracer()
     tracer.start()
     counter = VizCounter(tracer, "name")
     with self.assertRaises(Exception) as _:
         counter.a = ""
     with self.assertRaises(Exception) as _:
         counter.b = {}
     with self.assertRaises(Exception) as _:
         counter.c = []
     tracer.stop()
     tracer.clear()
コード例 #4
0
        err = 0
        for i in range(0, len(parameter_vector)):
            cost_derivative = get_cost_derivative(i - 1)
            err += abs(cost_derivative)
            temp_parameter_vector[i] = (
                parameter_vector[i] - LEARNING_RATE * cost_derivative
            )
        counter.cost = math.log(1+err)
        if numpy.allclose(
            parameter_vector,
            temp_parameter_vector,
            atol=absolute_error_limit,
            rtol=relative_error_limit,
        ):
            break
        parameter_vector = temp_parameter_vector
    print(("Number of iterations:", j))


def test_gradient_descent():
    for i in range(len(test_data)):
        print(("Actual output value:", output(i, "test")))
        print(("Hypothesis output:", calculate_hypothesis_value(i, "test")))


if __name__ == "__main__":
    with VizTracer(log_print=True, output_file=os.path.join(os.path.dirname(__file__), "../", "json/gradient_descent.json")) as tracer:
        counter = VizCounter(tracer, "log(1 + cost)")
        run_gradient_descent()
        test_gradient_descent()
コード例 #5
0

def g(a, b):
    a += h(a)
    b += 3
    # raise Exception("lol")


def f(a, b):
    # wthell.wth()
    a = a + 2
    ob.s = str(b)
    g(a + 1, b * 2)
    # wthell.wth()
    h(36)


def t(a):
    f(a + 1, a + 2)
    a += 3
    f(a + 5, 2)


tracer = VizTracer()
counter = VizCounter(tracer, "a")
ob = VizObject(tracer, "b")
tracer.start()
t(3)
tracer.stop()
tracer.save("vdb_basic.json")