This file contains 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
""" | |
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy). Edited by Geoffrey Churchill | |
BSD License | |
""" | |
import numpy as np | |
from sys import argv | |
try: | |
num_steps=int(argv[3]) | |
except IndexError: |
This file contains 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
(menu-bar-mode -1) | |
(setq inhibit-startup-screen t) | |
(setq inhibit-startup-echo-area-message "l") | |
(setq initial-major-mode 'fundamental-mode) | |
(setq initial-scratch-message nil) | |
(setq auto-save-default nil) | |
(setq make-backup-files nil) | |
(require 'package) | |
;;(add-to-list 'package-archives |
This file contains 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
{ | |
"editor.acceptSuggestionOnEnter": "off", | |
"editor.selectionClipboard": false, // Disable middle-click paste. | |
"telemetry.enableTelemetry": false, | |
"telemetry.enableCrashReporter": false, | |
"workbench.startupEditor": "none", | |
"window.zoomLevel": 3, | |
"window.restoreFullscreen": true, | |
"workbench.statusBar.visible": true, | |
"workbench.activityBar.visible": false, |
This file contains 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 Prelude hiding (zip) | |
-- `zip` accepts the first list and lazily returns a | |
-- function that accepts the second list and lazily | |
-- returns the list of pairs, so this implementation | |
-- is lazy in both arguments. | |
zip :: [a] -> [b] -> [(a, b)] | |
zip = | |
foldr | |
zipxs |
This file contains 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
ap :: [a -> b] -> [a] -> [b] | |
ap fs xs = go1 ([], fs) ([], xs) | |
where | |
go1 (fs, []) (_, xs) = [f x | x <- xs, f <- fs] -- No more fs: roundrobin seen fs on unseen xs. | |
go1 fs@(_, f : _) xs@(seenxs, _) = [f x | x <- seenxs] ++ go2 (step fs) xs -- Apply next f to seen xs and recur. | |
go2 (_, fs) (xs, []) = [f x | f <- fs, x <- xs] -- No more xs: roundrobin seen xs on unseen fs. | |
go2 fs@(seenfs, _) xs@(_, x : _) = [f x | f <- seenfs] ++ go1 fs (step xs) -- Apply seen fs to next x and recur. | |
step (seen, cur : unseen) = (cur : seen, unseen) -- Mark current element as seen. | |
-- E.g. to generate all triples |
This file contains 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
-- Lazy subsets of potentially infinite list (from https://stackoverflow.com/a/36101787). | |
subsets :: [a] -> [[a]] | |
subsets l = [] : go [[]] l | |
where | |
go _ [] = [] | |
go seen (cur : rest) = let next = (cur :) <$> seen in next ++ go (seen ++ next) rest | |
-- Lazy product of potentially infinite lists. | |
product :: [a] -> [b] -> [(a, b)] | |
product l r = go1 ([], l) ([], r) |
This file contains 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
:- use_module(library(clpfd)). | |
%% at(Dimensions, Index, Array, Element) -- array access. | |
at([], [], X, X). | |
at([D|Ds], [I|Is], A, X) :- | |
length(A, D), | |
nth1(I, A, AI), | |
at(Ds, Is, AI, X). | |
%% `Ds` is the size of each dimension of an array. `Is` is the list of all indices into an array with those dimensions. |
This file contains 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
% Implementation of call-by-name lambda calculus in Prolog using logic variables as lambda variables | |
% | |
% The grammar is: | |
% Term ::= Term-Term % abstraction: LHS is function body; RHS is parameter (Y-X instead of λX.Y) | |
% | Term+Term % application: LHS is function; RHS is argument (F+X instead of (F X)) | |
eval(Y-X, Y-X). % abstractions are left as-is | |
eval(F+X, Y) :- | |
copy_term(F,B), % copy before destructive unification of parameter in case F appears elsewhere | |
eval(B, Y0-X), % eval into what must be an abstraction and unify X with parameter |
This file contains 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
eos([], []). | |
% Relates a list to a partitioning of its elements into two subsequences (append/3 for subsequences). | |
list_subseq_subseq([]) --> eos. | |
list_subseq_subseq([H|S]) --> [H], list_subseq_subseq(S). | |
list_subseq_subseq([H|S]), [H] --> list_subseq_subseq(S). | |
% Relates a list to a partitioning of its elements into nonempty subsequences (append/2 for nonempty subsequences). | |
list_subseqs([], []). | |
list_subseqs([H|T], [[H|PT]|Ps]) :- |
This file contains 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
rewrite(L, R), [Skip] --> [Skip], rewrite(L, R). % Skip the current head. | |
rewrite(L, R), R --> L. % Match the current prefix and return. | |
rewrite(Rules) --> {member(L-R, Rules)}, rewrite(L, R). % Try a single rule. | |
normalize(P) --> P, normalize(P). % If at first you succeed, try, try again. | |
normalize(P) --> \+P. % P failed so list remains the same. | |
% Single-step rewrite with {"ab"->"x", "ca"->"y"}: | |
% ?- phrase(rewrite([[a,b]-[x], [c,a]-[y]]), [a,b,c,a,b,c], Out). | |
% Out = [a, b, c, x, c] ; |
OlderNewer