Esempio n. 1
0
import networkx as nx
import matplotlib.pyplot as plt

g = tfg.Graph()
g.initialize()

#--------------
# Create variables
a = tfg.Variable(5.0, name="a")
b = tfg.Variable(1.0, name="b")

# Create placeholder
x = tfg.Placeholder(name="x")

# Create hidden node y
y = tfg.Mul(a, x, name="y")

# Create output node z
z = tfg.Add(y, b, name="z")

session = tfs.Session()
output = session.run(z, {x: 1.0})  # z:operation
print(output)
print()
print("-------------------")
#--------------
# Create variables
# Not scalar, list
A = tfg.Variable([[1, 0], [0, -1]], name="A")
b = tfg.Variable([1, 1], name="b")
Esempio n. 2
0
import networkx as nx
import matplotlib.pyplot as plt

# g= graph.Graph()
g = tfg.Graph()
g.initialize()

# Create variables
a = tfg.Variable(5.0, name='a')
b = tfg.Variable(1.0, name='b')

# Create placeholder
x = tfg.Placeholder(name='x')

# Create hidden node y
y = tfg.Mul(a, x, name="y")

# Create output node z
z = tfg.Add(y, b, name="z")

#nx.draw_networkx(g, with_labels=True)
#plt.show(block=True)

session = tfs.Session()
output = session.run(z, {x: 1.0})
print(output)

print(z.input_nodes[0], z.input_nodes[1])
print(z.output)
print(z.consumers)
print(y.consumers[0])
Esempio n. 3
0
import tensorflux.graph as tfg
import tensorflux.session as tfs

apple_price = 100
apple_num = 2
tax = 1.1

g = tfg.Graph()

# Create variables
a = tfg.Variable(apple_price, name="a")
b = tfg.Variable(apple_num, name="b")
c = tfg.Variable(tax, name="c")

# Create Mul operation node
d = tfg.Mul(a, b, name="d")

# Create Mul operation node
e = tfg.Mul(d, c, name="e")

session = tfs.Session()
# forward
total_apple_price = session.run(d, verbose=False)
print("total_apple_price: {:f}".format(float(total_apple_price)))
final_price = session.run(e, verbose=False)
print("final_price: {:f}".format(float(final_price)))

print()

#backward
d_in = 1
Esempio n. 4
0
tax = 1.1

g = tfg.Graph()

# Create variables
a = tfg.Variable(apple_price, name="a")
b = tfg.Variable(apple_num, name="b")

c = tfg.Variable(orange_price, name="c")
d = tfg.Variable(orange_num, name="d")

e = tfg.Variable(tax, name="e")

# Create Mul operation node
f = tfg.Mul(a, b, name="f")
g = tfg.Mul(c, d, name="g")

# Create Add operation node
h = tfg.Add(f, g, name="h")

# Create Mul operation node
i = tfg.Mul(h, e, name="i")

session = tfs.Session()
# forward
final_price = session.run(i, verbose=False)
print("final_price: {:f}".format(float(final_price)))

print()
Esempio n. 5
0
 def __init__(self, weight_node, input_node, bias_node):
     # Create hidden node y
     y = tfg.Mul(weight_node, input_node)  #곱 연산 클래스를 생성
     # Create output node z
     z = tfg.Add(y, bias_node)  #합 연산 클래스를 생성
Esempio n. 6
0
#import networkx as nx
#import matplotlib.pyplot as plt

g = tfg.Graph()  # 컴퓨테이션 그래프 클래스를 생성
#g.initialize() # 컴퓨테이션 그래프 클래스를 초기화
#"""
# Create variables
a = tfg.Variable(5.0, name="a")  #변수 클래스 a를 생성하고 초기화
b = tfg.Variable(-1.0, name="b")  #변수 클래스 b를 생성하고 초기화

# Create placeholder
x = tfg.Placeholder(name="x")  #플레이스홀더는 이후 입력할 값으로 현재는 값까지는 초기화하지 않음

# Create hidden node y
y = tfg.Mul(a, x, name="y")  #곱 연산 클래스를 생성

# Create output node z
z = tfg.Add(y, b, name="z")  #합 연산 클래스를 생성

#nx.draw_networkx(g, with_labels=True)
#plt.show(block=True)

# 수행~~~~~~~~~~~~~~~~~~~~~~
session = tfs.Session()
output = session.run(z, {x: 1.0})
print(output)
output = session.run(z, {x: 2.0})
print(output)
output = session.run(z, {x: 3.0})
print(output)
Esempio n. 7
0
 def __init__(self, weight_node, input_node, bias_node):
     y = tfg.Mul(weight_node, input_node)
     z = tfg.Add(y, bias_node)