Skip to content

Instantly share code, notes, and snippets.

View dongguosheng's full-sized avatar

董国盛 dongguosheng

View GitHub Profile
@dongguosheng
dongguosheng / mail_util.py
Last active August 29, 2015 14:18
Send mail util with attachment
# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import smtplib
class Message(object):
'''Email util.'''
def __init__(self, mailto_list=['xxxxxx@qq.com'], mail_host='smtp.126.com',
mail_user='yyyyyy', mail_password='zzzzzz', mail_postfix='126.com', attach_file_list=[]):
@dongguosheng
dongguosheng / lr.py
Last active February 29, 2016 13:05
a simple logistic regression implementation, test on heart_scale dataset.
# -*- coding: utf-8 -*-
'''
Feature vectors are column vectors.
X, n * m, n -> feature dim, m -> sample number
Y, 1 * m, row vector
theta/weight/beta, n * 1, column vector
gradient, n * 1, column vector
gradient = X * (Y - sigmoid(theta' * X))'
@dongguosheng
dongguosheng / solve.py
Last active March 1, 2016 12:55
toy code about gradient descent, newton method.
# -*- coding: gbk -*-
import numpy as np
def foo(x):
return x**2 + 2*x + 1
def g(x):
return 2*x + 2
@dongguosheng
dongguosheng / kmeans.h
Last active April 14, 2016 11:46
a simple k-means implementation, use c++11 and openmp
#ifndef KMEANS_H
#define KMEANS_H
#include <vector>
#include <set>
#include <random>
#include <ctime>
#include <cfloat>
#include <cassert>
#include <cmath>
#include <iostream>
@dongguosheng
dongguosheng / test_omp.cpp
Last active April 13, 2016 11:40
compare normal, c++11 thread and openmp
#include <iostream>
#include <ctime>
#include <random>
#include <vector>
#include <thread>
#include <omp.h>
using namespace std;
const static int TOTAL_SIZE = 100000;
# -*- coding: gbk -*-
import math
def cal_ndcg(r_list, k):
idcg = cal_dcg(sorted(r_list, reverse=True), k)
if idcg <= 1e-10:
return 1.0
return cal_dcg(r_list, k) / idcg