Skip to content

Instantly share code, notes, and snippets.

@pranavkantgaur
pranavkantgaur / find_minimum_number_partitions.py
Last active April 2, 2020 16:55
The script computes the minimum number of partitions of input string with respect to a given list of strings, if exists. Refer: https://youtu.be/tOD6g7rF7NA?t=268
input_string = "31495"
fav_strings = ["31", "314", "3149", "495"]
INF = len(input_string)
def substring_match(pos):
match_lengths = []
for fav_string in fav_strings:
if len(fav_string) + pos <= len(input_string):
if fav_string in input_string[pos: pos + len(fav_string)]:
@pranavkantgaur
pranavkantgaur / localize_fiducials.py
Last active January 29, 2019 10:44
This code localizes fiducials given corresponding fiducial detection results.
import nibabel as nib
import pcl
import numpy as np
from pcl import IterativeClosestPoint
from pcl import pcl_visualization
# used for icp rigid alignemnt of fiducial candidate with synthetic fiducial for lits localization
def generate_synthetic_fiducial():
@pranavkantgaur
pranavkantgaur / annealed_epsilon_greedy_agent_cartpole_agent.py
Last active December 28, 2018 17:53
annealed epsilon greedy agent for CartPole problem
'''this code implements annealed epsilon greedy ml agent for CartPole problem '''
import numpy as np
import gym
class myAnnealedEpsilonGreedyCartPoleAgent(object):
def __init__(self, action_space):
self.action_space = action_space
assert (action_space, gym.spaces.discrete.Discrete), "unsupported action space for now."
def act(self, state, reward, time_step, done, default_epsilon = 0.98):
# TODO compute epsilon for current iteration
@pranavkantgaur
pranavkantgaur / epsilon_greedy_rl_agent.py
Created December 21, 2018 04:16
RL agent employing epsilon greedy action strategy
# coding: utf-8
import os
import logging
import tempfile
import numpy as np
import gym
#from gym.wrappers.monitoring import Monitor
class myEphsilonGreedyAgent(object):
@pranavkantgaur
pranavkantgaur / discounted_future_return.py
Created December 21, 2018 04:15
Calculating discounted future return for agent
''' Gets list of furture rewards, associates discount factor with future rewards '''
def discounted_future_return(rewards, gamma=0.98):
discounted_returns = [0 for _ in rewards]
discounted_returns[-1] = rewards[-1]
for t in range(len(rewards) - 2. -1, -1):
discounted_returns[t] = rewards[t] + gamma * discounted_returns[t+1]
return discounted_returns
@pranavkantgaur
pranavkantgaur / random_cart_pole_agent.py
Last active December 21, 2018 04:13
Random agent for Cart Pole environment
import os
import logging
import tempfile
import numpy as np
import gym
#from gym.wrappers.monitoring import Monitor
class RandomAgent(object):
def __init__ (self, action_space):
@pranavkantgaur
pranavkantgaur / nvcontrol-warp-blend-with-file-configuration-import-ximage.c
Last active February 27, 2019 11:44
nvcontrol-warp-blend.c with customizations
/*
* Copyright (c) 2013 NVIDIA Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@pranavkantgaur
pranavkantgaur / tetgenMeshSurface.cpp
Created December 26, 2016 10:34
Tetgen algorithm for surface meshing input PLC
void tetgenmesh::meshsurface()
{
arraypool *ptlist, *conlist;
point *idx2verlist;
point tstart, tend, *pnewpt, *cons;
tetgenio::facet *f;
tetgenio::polygon *p;
int end1, end2;
int shmark, i, j;
@pranavkantgaur
pranavkantgaur / predicates.c
Created April 3, 2016 13:54
Schewchuck robust predicates
/*****************************************************************************/
/* */
/* Routines for Arbitrary Precision Floating-point Arithmetic */
/* and Fast Robust Geometric Predicates */
/* (predicates.c) */
/* */
/* May 18, 1996 */
/* */
/* Placed in the public domain by */
/* Jonathan Richard Shewchuk */
@pranavkantgaur
pranavkantgaur / tetgen.cxx
Created April 3, 2016 13:53
Tetgen source file
This file has been truncated, but you can view the full file.
///////////////////////////////////////////////////////////////////////////////
// //
// TetGen //
// //
// A Quality Tetrahedral Mesh Generator and A 3D Delaunay Triangulator //
// //
// Version 1.5 //
// May 31, 2014 //
// //
// Copyright (C) 2002--2014 //