Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 58 additions & 55 deletions Neuronal-Red/temperature_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,61 @@

import numpy as np

# Input data
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=np.float32)
fahrenheit = (celsius*1.8) + 32


# Model definition
Input_layer = tf.keras.layers.Input((1,))
hidden1 = tf.keras.layers.Dense(units=2) #Dense Layer With 2 units so as to not overfit the data
output = tf.keras.layers.Dense(units=1)
model = tf.keras.Sequential([Input_layer,hidden1, output])
# Model compilation
model.compile(
optimizer=tf.keras.optimizers.Adam(0.1),
loss='mean_squared_error'
)

# Model training
epochs = 100
print("Starting training...")
history = model.fit(celsius, fahrenheit, epochs=epochs, verbose=False)
loss = history.history["loss"]
print("Model trained!")

# Making a prediction
print("Let's make a prediction!")
result = model.predict(np.array([89.0]))
print("The result is " + str(result) + " fahrenheit")
print(f"True value = {(89.0*1.8) +32}")

# Viewing the internal variables of the model
print("Internal model variables")
print(hidden1.get_weights())
# print(hidden2.get_weights())
print(output.get_weights())

# loss changes
plt.figure(figsize = (10,10))
plt.subplot(1,2,1)
plt.plot(range(epochs),loss)
plt.xlabel("Epochs")
plt.ylabel("loss")
plt.title("losse over epochs")

# true values vs predicted values
plt.subplot(1,2,2)
x_test = np.random.randint(0,100,[20,1])
y_test = (x_test*1.8) +32
y_pred = model.predict(x_test)

plt.scatter(x_test, y_test, color='blue', label='True Values')
plt.scatter(x_test, y_pred, color='red', label='Predicted Values')
plt.xlabel("True values")
plt.ylabel("predicted values")
plt.title("True values vs Predicted values")
plt.show()
try:
# Input data
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=np.float32)
fahrenheit = (celsius*1.8) + 32


# Model definition
Input_layer = tf.keras.layers.Input((1,))
hidden1 = tf.keras.layers.Dense(units=2) #Dense Layer With 2 units so as to not overfit the data
output = tf.keras.layers.Dense(units=1)
model = tf.keras.Sequential([Input_layer,hidden1, output])
# Model compilation
model.compile(
optimizer=tf.keras.optimizers.Adam(0.1),
loss='mean_squared_error'
)

# Model training
epochs = 100
print("Starting training...")
history = model.fit(celsius, fahrenheit, epochs=epochs, verbose=False)
loss = history.history["loss"]
print("Model trained!")

# Making a prediction
print("Let's make a prediction!")
result = model.predict(np.array([89.0]))
print("The result is " + str(result) + " fahrenheit")
print(f"True value = {(89.0*1.8) +32}")

# Viewing the internal variables of the model
print("Internal model variables")
print(hidden1.get_weights())
# print(hidden2.get_weights())
print(output.get_weights())

# loss changes
plt.figure(figsize = (10,10))
plt.subplot(1,2,1)
plt.plot(range(epochs),loss)
plt.xlabel("Epochs")
plt.ylabel("loss")
plt.title("losse over epochs")

# true values vs predicted values
plt.subplot(1,2,2)
x_test = np.random.randint(0,100,[20,1])
y_test = (x_test*1.8) +32
y_pred = model.predict(x_test)

plt.scatter(x_test, y_test, color='blue', label='True Values')
plt.scatter(x_test, y_pred, color='red', label='Predicted Values')
plt.xlabel("True values")
plt.ylabel("predicted values")
plt.title("True values vs Predicted values")
plt.show()
except Exception as e:
printf("Exception occured!", e)
77 changes: 49 additions & 28 deletions Password_Manager/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,69 @@

def main_menu():
"""Display the main menu and get the user's choice."""
menu = [
"---------------------|",
"Password Manager App |",
"---------------------|",
"1. Create password |",
"2. Check password |",
"3. Edit password |",
"4. Delete password |",
"5. Exit |",
"---------------------|"
]
print("\n".join(menu))
return input("Pick a number: ")
try:
menu = [
"---------------------|",
"Password Manager App |",
"---------------------|",
"1. Create password |",
"2. Check password |",
"3. Edit password |",
"4. Delete password |",
"5. Exit |",
"---------------------|"
]
print("\n".join(menu))
return input("Pick a number: ")
except Exception as e:
print(f"An error occurred: {e}")
return


def validate_aim(aim):
"""Validate if the aim is not empty."""
if not aim:
display_message("Aim unspecified or empty. Please specify an 'aim' value.", Fore.RED)
try:
if not aim:
display_message("Aim unspecified or empty. Please specify an 'aim' value.", Fore.RED)
return False
return True
except Exception as e:
print("Exception occured: ", e)
return False
return True

def read_csv_file():
"""Read the CSV file and return the data as a list of dictionaries."""
if not os.path.isfile(PASSWORD_FILE):
try:
if not os.path.isfile(PASSWORD_FILE):
return []
with open(PASSWORD_FILE, "r") as csvfile:
return list(csv.DictReader(csvfile))
except Exception as e:
print("Exception occured: ", e)
return []
with open(PASSWORD_FILE, "r") as csvfile:
return list(csv.DictReader(csvfile))

def write_csv_file(data):
"""Write the data to the CSV file."""
with open(PASSWORD_FILE, "w", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=["aim", "password"])
writer.writeheader()
writer.writerows(data)
try:
with open(PASSWORD_FILE, "w", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=["aim", "password"])
writer.writeheader()
writer.writerows(data)
except Exception as e:
print("Exception occured: ", e)
return

def password_generator():
"""Generate a random password with lowercase, uppercase, punctuation, and numeric characters."""
char_sets = [string.ascii_lowercase, string.ascii_uppercase, string.punctuation, string.digits]
password = [random.choice(char_set) for char_set in char_sets]
password.extend(random.choices("".join(char_sets), k=STRING_LENGTH + PUNCTUATION_LENGTH + 4 - len(char_sets)))
random.shuffle(password)
return "".join(password)
try:
char_sets = [string.ascii_lowercase, string.ascii_uppercase, string.punctuation, string.digits]
password = [random.choice(char_set) for char_set in char_sets]
password.extend(random.choices("".join(char_sets), k=STRING_LENGTH + PUNCTUATION_LENGTH + 4 - len(char_sets)))
random.shuffle(password)
return "".join(password)
except Exception as e:
print("An error occurred: ", e)


def display_message(message, color=Fore.GREEN):
"""Display a message in the specified color."""
Expand Down
16 changes: 10 additions & 6 deletions tictactoe/tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,16 @@ def max_value(board):

def min_value(board):
"""Returns the minimum value (for O) of a move."""
if terminal(board):
return utility(board)
value = float('inf')
for action in actions(board):
value = min(value, max_value(result(board, action)))
return value
try:
if terminal(board):
return utility(board)
value = float('inf')
for action in actions(board):
value = min(value, max_value(result(board, action)))
return value
except Exception as e:
print(f"Exception: {e}")
return None


if __name__ == "__main__":
Expand Down