<jupyter_start><jupyter_text>Solutions<jupyter_code># Activation (sigmoid) function
def sigmoid(x):
    return 1 / (1 + np.exp(-x))

def output_formula(features, weights, bias):
    return sigmoid(np.dot(features, weights) + bias)

def error_formula(y, output):
    return - y*np.log(output) - (1 - y) * np.log(1-output)

def update_weights(x, y, weights, bias, learnrate):
    output = output_formula(x, weights, bias)
    d_error = y - output
    weights += learnrate * d_error * x
    bias += learnrate * d_error
    return weights, bias
# My solutions
def sigmoid(x):
    return 1/(1+np.exp(-x))

# Output (prediction) formula
def output_formula(features, weights, bias):
    return sigmoid(np.matmul(features,weights)+bias)

# Error (log-loss) formula
def error_formula(y, output):
    return -(y*np.log(output)+(1-y)*np.log(1-output))

# Gradient descent step
def update_weights(x, y, weights, bias, learnrate):
    adjust = y-output_formula(x,weights,bias)
    for i in range(len(weights)):
        weights[i]+=learnrate*adjust*x[i]
    bias+=learnrate*adjust
    return weights,bias<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14107142857142857, 'fraction_numerical': 0.007142857142857143, 'mean_word_length': 4.415458937198068, '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': '52081', 'license': 'MIT', 'n_tokens_mistral': 406, 'n_tokens_neox': 394, 'n_words': 91, 'path': 'intro-neural-networks/gradient-descent/GradientDescentSolutions.ipynb', 'repo_name': 'GeoffKriston/deep-learning-v2-pytorch', 'size': '1120'}