Skip to content

Instantly share code, notes, and snippets.

# python3
import random
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--draw_cards_number', type=int, default=3)
parser.add_argument('-i', '--iteration', type=int, default=100000)
@Jerrynet
Jerrynet / contrastive_loss.py
Last active May 11, 2021 14:39
Tensorflow contrastive loss (Numeric stable)
# Contrastive Loss
# by Che-Wei Lin
# Under the Simplified BSD License
import tensorflow as tf
from tensorflow.python.framework.function import Defun
def contrastive_loss(margin, threshold=1e-5):
"""Contrastive loss:
@Jerrynet
Jerrynet / SwiftLAObject.swift
Last active August 29, 2015 14:12
Swift Example: LinearAlgebra(LA Object) in Accelerate Framework
import Accelerate
//Perform a 3x3 matrix production, axb
var a:[Double] = [1,1,0, 0,1,0, 0,0,1]
var b:[Double] = [1,2,3, 4,5,6, 7,8,9]
//Swift cannot understand LA constants, need to cast them
var aObj:la_object_t = la_matrix_from_double_buffer(&a, 3, 3, 3, la_hint_t(LA_NO_HINT), la_attribute_t(LA_DEFAULT_ATTRIBUTES))
var bObj:la_object_t = la_matrix_from_double_buffer(&b, 3, 3, 3, la_hint_t(LA_NO_HINT), la_attribute_t(LA_DEFAULT_ATTRIBUTES))
@Jerrynet
Jerrynet / MDMatrix.swift
Last active August 29, 2015 14:06
Multi-Dimensional Matrix
import Cocoa
//No bounds checking
struct Matrix {
let dims:[Int]
let increaseDim:[Int]
var grid: [Double]
init(dim: Int...) {
self.dims = dim
var tmpInDim:[Int] = [1]