<jupyter_start><jupyter_text>Logistic Regression<jupyter_code>import theano
import theano.tensor as T
# Logisitic Function
x = T.dmatrix('x')
s = 1 / (1 + T.exp(-x))
logistic = theano.function([x], s)

# test
logistic([[0,1],[-1,-2]])
# Alternate formulation
s2 = (1 + T.tanh(x / 2)) / 2
logistic2 = theano.function([x], s2)

# test
logistic2([[0,1],[-1,-2]])
# Computing more than one thing at the same time
a, b = T.dmatrices('a','b')
diff = a - b
abs_diff = abs(diff)
diff_squared = diff**2
f = theano.function([a,b], [diff, abs_diff, diff_squared])
f([[1, 1], [1, 1]],[[0, 1], [2, 3]])
# Setting a Default Value for an argument
from theano import Param
from theano import function
x, y = T.dscalars('x', 'y')
z = x + y
f = function([x, Param(y, default=1)], z)

print f(33)

print f(33,2)
x, y, w = T.dscalars('x','y','w')
z = (x + y) * w
f = function([x, Param(y, default=1), Param(w,default=2, name='w_by_name')], z)

print f(33)
print f(33, 2)
print f(33, 0, 1)
print f(33, w_by_name=1)
print f(33, w_by_name=1, y=0)
# Using shared variables
from theano import shared
state = shared(0)
inc = T.iscalar('inc')
accumulator = function([inc], state, updates=[(state, state+inc)])
state.get_value()
accumulator(1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19839357429718876, 'fraction_numerical': 0.04176706827309237, 'mean_word_length': 5.107843137254902, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '30099', 'license': 'MIT', 'n_tokens_mistral': 549, 'n_tokens_neox': 527, 'n_words': 143, 'path': '.ipynb_checkpoints/Mike_Theano_Tutorial-checkpoint.ipynb', 'repo_name': 'WhalerWatch/WhaleWatch', 'size': '1245'}