Skip to content

Instantly share code, notes, and snippets.

import pandas as pd
import numpy as np
import pickle
np.random.seed(1212)
import keras
from keras.models import Model
from keras.layers import *
from keras import optimizers
from keras.layers import Input, Dense
from keras.models import Sequential
model = Sequential()
model.add(Conv2D(30, (5, 5), input_shape=(1 , 28, 28), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(15, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(50, activation='relu'))
model.add(Dense(13, activation='softmax'))
model.fit(np.array(l), cat, epochs=10, batch_size=200,shuffle=True,verbose=1)
model_json = model.to_json()
with open("model_final.json", "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("model_final.h5")
json_file = open('model_final.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model_final.h5")
@vipul79321
vipul79321 / radius_DHV.py
Created June 20, 2020 11:10
Pseudo code for radius_DHV method
Input : Sage Graph object G
Initializing LB = 0, UB = INFINITY, ecc_lower_bound = [0 for i in range(vertices)]
# Algorithm
while LB < UB:
# Select vertex with minimum eccentricity lower bound, say u
# Compute shortest distances from u to other vertices using BFS or Dijkstra
distances = BFS(G, u) or Dijkstra(G, u)
UB = min(UB, eccentricity(u))
Input : Sage Graph object G
Initializing LB = 0, UB = INFINITY, ecc_lower_bound = [0 for i in range(vertices)],
ecc_upper_bound = [Infinity for i in range(vertices)], active = list(G)
# Algorithm
while LB < UB and active:
# Select vertex with maximum eccentricity upper bound in active, say u.
# Compute shortest distances from u to other vertices using BFS or Dijkstra
# Remove u from active vertices
distances = BFS(G, u) or Dijkstra(G, u)
Input : Sage Graph object G
Initializing: ecc_lower_bound = [0 for i in range(vertices)],
ecc_upper_bound = [Infinity for i in range(vertices)], active = list(G)
# Algorithm
while active:
# Select vertex with minimum eccentricity in active, say u.
# Compute shortest distances from u to other vertices using BFS or Dijkstra
# Remove u from active vertices
distances = BFS(G, u) or Dijkstra(G, u)
Input : Sage DiGraph object G
# Obtain Lower bound on the diameter and vertex m with low eccentricity
# Using 2Dsweep method
LB, s, m, d = 2Dsweep(G)
# Compute forward distances from m to all vertices in G
distances_1 = forward_BFS(G, m) or forward_Dijkstra(G, m)
# Compute backward distances from m to all vertices in G
@vipul79321
vipul79321 / indian_market_yahoo_finance_ticker_to_stock.json
Created June 30, 2021 18:55
A dictionary of yahoo finance ticker symbol to ticker name for Indian Market
{
"1STCUS.BO": "The First Custodian Fund (I) Ltd.",
"20MICRONS.BO": "20 Microns Limited",
"20MICRONS.NS": "20 Microns Limited",
"21STCENMGM.BO": "Twentyfirst Century Management Services Limited",
"3IINFOTECH.BO": "3i Infotech Limited",
"3IINFOTECH.NS": "3i Infotech Limited",
"3MINDIA.BO": "3M India Limited",
"3MINDIA.NS": "3M India Limited",
"4THGEN.BO": "Fourth Generation Information Systems Limited",