This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def dijkstra(cost_matrix, destination_node): | |
open_list = [] | |
closed_list = set() | |
number_of_nodes = len(cost_matrix) | |
# (cum_cost, (previous_node, current_node)) | |
heapq.heappush(open_list, (0, (0, 0))) | |
while open_list: | |
current_node = heapq.heappop(open_list) | |
# if the current node not already expanded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Pedro Borges | |
import heapq | |
import sys | |
def knapsack(val, wt, total_w): | |
elements = transform_to_list_dict(val, wt) | |
open_list = [] | |
closed_list = [] | |
# set to mark the nodes already seen | |
generated_nodes = set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from gym import spaces | |
class MyEnv(gym.Env): | |
"""Custom Environment""" | |
metadata = {'render.modes': ['human']} | |
def __init__(self): | |
super(Snake, self).__init__() | |
# necessary internal env id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import pandas as pd | |
from torch.utils.data import Dataset, DataLoader | |
class ExampleDataset(Dataset): | |
"""Example Dataset""" | |
def __init__(self, csv_file): | |
""" | |
csv_file (string): Path to the csv file containing data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.optim as optim | |
import torch.nn as nn | |
# instantiate your network that should be defined by you | |
net = Net() | |
# create your optimizer | |
optimizer = optim.SGD(net.parameters(), lr=0.01) | |
# define your criterion for optimization | |
criterion = nn.MSELoss() | |
# dat_set comes from somewhere | |
for data in data_set: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
class Net(nn.Module): | |
def __init__(self): | |
super(Net, self).__init__() | |
# Defining 3 linear layers but NOT the way they should be connected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import flask | |
import json | |
from flask import Response | |
app = Flask(__name__) | |
@app.route('/test',methods=['GET']) | |
def test(): | |
''' | |
GET: Receives the request in /test route and returns a response containing {"response": "test"} |