Skip to content

Instantly share code, notes, and snippets.

View Madhivarman's full-sized avatar
🏠
Working from home

Madhivarman Madhivarman

🏠
Working from home
  • Pluto7
  • Bengaluru
View GitHub Profile
@Madhivarman
Madhivarman / Bruteforce.java
Last active May 20, 2022 05:16
String Pattern matching using BruteForce Algorithm
//brute force algorithm
//string matching
import java.io.*;
import java.util.Scanner;
class Bruteforce{
//called function
public static int bruteforce(String text,String tobematched){
int length = text.length();//length of the text
int plength = tobematched.length();//length of the pattern;
@Madhivarman
Madhivarman / multiprocess.py
Created January 26, 2020 18:47
Sample script in Multiprocessing
import time
import datetime
import os
import pandas as pd
from multiprocessing import Process, Queue, current_process
def do_something(fromprocess):
time.sleep(1)
print("Operation Ended for Process:{}, process Id:{}".format(
current_process().name, os.getpid()
@Madhivarman
Madhivarman / SelectionSort.java
Created September 5, 2017 14:47
Selection Sort using single Loop
import java.io.*;
public class SelectionSort{
static int i;
static int temp,element;
//selection sorting done here
public static void SelectionSort(int[] arr,int n){
//while condtion to check the loop and increment
int smallest = arr[0];
int init = 0;
@Madhivarman
Madhivarman / model_demo.py
Last active June 6, 2019 12:57
TensorFlow Code - Training a model to count how many ones are there in the string.
#train model to count number of 1's present in the string
import numpy as np
from random import shuffle
#import necessary libarary
import tensorflow as tf
training_data = ['{0:020b}'.format(i) for i in range(2**20)]
shuffle(training_data)
train_input = [map(int,i) for i in training_data]
ti = [] #list to store each tensor
from collections import defaultdict
class Graph():
#initial declaration
def __init__(self):
self.graph = defaultdict(list)
#add edge between two vertices
def addedge(self,src,dist):
import pandas as pd
import numpy as np
#create a dummy data
user_id = [x for x in range(10000)]
recency = np.random.randint(low=1, high=10, size=10000)
monetary = np.random.randint(low=1, high=10, size=10000)
frequency = np.random.randint(low=1, high=10, size=10000)
import tensorflow as tf
import os
from tensorflow.python.keras.applications import ResNet50
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, Flatten, GlobalAveragePooling2D
from tensorflow.python.keras.applications.resnet50 import preprocess_input
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
@Madhivarman
Madhivarman / learntomake5.py
Created May 10, 2018 18:35
Using Reinforcement Learning - QTable Algorithm algorithms learns to make 5 within three attempts. Input number ranges from 1 to 12.
import random
import numpy as np
class Game:
def __init__(self):
self.reset()
def reset(self):
self.current_number = random.randrange(1,12)
@Madhivarman
Madhivarman / pong.py
Created May 8, 2018 13:27
A Neural Network model that learns to play a PONG game from the image RAW pixels.
import gym
import numpy as np
env = gym.make("Pong-v0")
observation = env.reset()
#hyperparameters
episode_number = 0
batch_size=10 #how many episodes to wait before moving the weights
gamma = 0.99 #discount factor for reward
"""Sentence segmentation, means, to split a given paragraph of text into sentences, by identifying the sentence boundaries.
In many cases, a full stop is all that is required to identify the end of a sentence, but the task is not all that simple.
This is an open ended challenge to which there are no perfect solutions. Try to break up given paragraphs into text into
individual sentences. Even if you don't manage to segment the text perfectly, the more sentences you identify and display
correctly, the more you will score."""
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize