python中变量的值通过什么访问_如何在一个类中访问一个ano符号变量的值?

我想访问我的\u classifier.y\u二进制文件的值。我的目标是计算_分类器.错误. 在

我知道如何使用eval来获取我的分类器的值,但是我不知道当输入是自参数时如何使用它。在

谢谢# imports

import theano

import theano.tensor as T

import numpy as np

import matplotlib.pyplot as plt

import os, subprocess

class Perceptron(object):

"""Perceptron for the last layer

"""

def __init__(self, input, targets, n_features):

""" Initialize parameters for Perceptron

:type input:theano.tensor.TensorType

:param input:symbolic variable that describes the

input of the architecture

:type targets:theano.tensor.TensorType

:param targets:symbolic variable that describes the

targets of the architecture

:type n_features:int

:param n_features:number of features

(including "1" for bias term)

"""

# initilialize with 0 the weights W as a matrix of shape

# n_features x n_targets

self.w = theano.shared( value=np.zeros((n_features), dtype=theano.config.floatX),

name='w',

borrow=True

)

self.y_hat = T.nnet.sigmoid(T.dot(input,self.w))

self.y_binary = self.y_hat>0.5

self.binary_crossentropy = T.mean(T.nnet.binary_crossentropy(self.y_hat,targets))

self.error= T.mean(T.neq(self.y_binary, targets))

# create training data

features = np.array([[1., 0., 0],[1., 0., 1.], [1.,1.,0.], [1., 1., 1.]])

targets = np.array([0., 1., 1., 1])

n_targets = features.shape[0]

n_features = features.shape[1]

# Symbolic variable initialization

X = T.matrix("X")

y = T.vector("y")

my_classifier = Perceptron(input=X, targets=y,n_features=n_features)

cost = my_classifier.binary_crossentropy

error = my_classifier.error

gradient = T.grad(cost=cost, wrt=my_classifier.w)

updates = [[my_classifier.w, my_classifier.w-gradient*0.05]]

# compiling to a theano function

train = theano.function(inputs = [X,y], outputs=cost, updates=updates, allow_input_downcast=True)

# iterate through data

# Iterate through data

l = np.linspace(-1.1,1.1)

cost_list = []

for idx in range(500):

cost = train(features, targets)

if my_classifier.error==0:

break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值