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
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| module ProximalGradientMethod where | |
| import Data.Foldable | |
| import Data.Reflection (Reifies) | |
| import qualified Data.Vector.Storable as V | |
| import Numeric.AD | |
| import Numeric.AD.Mode.Reverse |
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
| sig E { | |
| join, meet : E -> one E | |
| } | |
| one sig top, bot in E {} | |
| fact { | |
| all x, y, z : E { | |
| -- commutativity | |
| x.join[y] = y.join[x] | |
| x.meet[y] = y.meet[x] |
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
| module Bug where | |
| import Control.Monad.Primitive | |
| import qualified Data.HashTable.ST.Basic as H | |
| data Symbol a = Symbol | |
| data Node s a = Node | |
| data Rule s a = Rule (Node s a) |
moved to numerical-optimization-sandbox.
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
| module CohensKappa where | |
| import Data.Hashable | |
| import qualified Data.HashMap.Strict as HashMap | |
| -- | Cohen's kappa coefficient (κ) | |
| -- | |
| -- https://en.wikipedia.org/wiki/Cohen%27s_kappa | |
| cohensKappa :: (Hashable c, Fractional a) => [(c,c)] -> a | |
| cohensKappa xs = (po - pe) / (1 - pe) |
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 typing import Literal, Optional, Tuple, overload | |
| @overload | |
| def f(with_extra_info: Literal[False]) -> Tuple[int, int]: ... | |
| @overload | |
| def f(with_extra_info: Literal[True]) -> Tuple[int, int, str]: ... | |
| # This overload is necessafy for type checking the last `f(with_extra_info)`. | |
| @overload |
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
| {-# OPTIONS_GHC -Wall #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| {-# LANGUAGE RecordWildCards #-} | |
| -- https://en.wikipedia.org/wiki/Okapi_BM25 | |
| module OkapiBM25 | |
| ( Database | |
| , mkDatabase | |
| , query | |
| ) where |
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 psycopg2 | |
| dsn = "postgresql://user:password@localhost:5432/" | |
| db_name = "test_db" | |
| conn = psycopg2.connect(dsn) | |
| try: | |
| conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | |
| with conn.cursor() as cur: |
NewerOlder