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 math | |
import numpy as np | |
class Softmax: | |
def forward(self, x): | |
return np.exp(x) / np.exp(x).sum() | |
def backward(self, y, target): | |
return y - target | |
def loss(self, y, target): | |
return - np.sum( np.log(y) * target ) |
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
# -*- coding: utf-8 -*- | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') |
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
from django.shortcuts import render | |
from rest_framework import generics | |
from rest_framework import filters | |
from .models import Image, Tag | |
from .serializers import ImageModelSerializer, TagModelSerializer | |
class ImageList(generics.ListCreateAPIView): | |
queryset = Image.objects.all() |
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
from django.shortcuts import render | |
from rest_framework import generics | |
from rest_framework import filters | |
from .models import Image, Tag | |
from .serializers import ImageModelSerializer, TagModelSerializer | |
class ImageList(generics.ListCreateAPIView): | |
queryset = Image.objects.all() |
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
from django.conf.urls import url | |
from api import views | |
urlpatterns = [ | |
url(r'images/$', views.ImageList.as_view()), | |
url(r'images/(?P<pk>[0-9a-zA-Z-]*)$', views.ImageDetail.as_view(), name='image-detail'), | |
url(r'tags/$', views.TagList.as_view()), | |
url(r'tags/(?P<pk>[0-9a-zA-Z-]*)$', views.TagDetail.as_view(), name='tag-detail'), | |
] |
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
from django.shortcuts import render | |
from rest_framework import generics | |
from .models import Image, Tag | |
from .serializers import ImageModelSerializer, TagModelSerializer | |
class ImageList(generics.ListCreateAPIView): | |
queryset = Image.objects.all() | |
serializer_class = ImageModelSerializer |
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
from rest_framework import serializers | |
from .models import Image, Tag | |
class _ImageModelSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Image | |
class _TagModelSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Tag |
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
from django.db import models | |
import uuid | |
class Image(models.Model): | |
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) | |
url = models.CharField(max_length=1024) | |
updated = models.DateTimeField(auto_now=True, db_index=True) | |
created = models.DateTimeField(auto_now_add=True, db_index=True) | |
def __str__(self): |
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 theano | |
import sklearn.datasets | |
# Generate synthetic data | |
N_CLASSES = 3 | |
X, y = sklearn.datasets.make_classification(n_features=2, n_redundant=0, | |
n_classes=N_CLASSES, n_clusters_per_class=1) | |
# Convert to theano floatX | |
X = X.astype(theano.config.floatX) | |
# Labels should be ints | |
y = y.astype('int32') |
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 numpy | |
def SR1(derivate, point, direction, step_length, Bk, epsilon=1e-6): | |
sk = direction * step_length | |
yk = numpy.array(derivate(point + sk)) - numpy.array(derivate(point)) | |
tk = sk - Bk.dot( yk ) | |
# check positive definite | |
if abs(numpy.dot(tk, yk)) > epsilon: | |
_ = numpy.matrix( tk ) | |
_ = _.transpose().dot( _ ) / _.dot( yk ) |
NewerOlder