mxnet failed to infer type - deep-learning

My mxnet code - which consists of a series of complex connections and slicing raises the following error:
Error in operator concat0: [03:03:51] src/operator/./concat-inl.h:211: Not enough information to infer type in Concat.
Im not sure how to interpret that or what information to provide to help debug it. Concat0 is part of the operation:
# Define take_column function as transpose(take(transpose(x), i))
for i in range(47):
y_hat_lt = take_column(y_hat,
mx.sym.concat(mx.sym.slice(some_indices, begin=i, end=i+1), self.label_dim + mx.sym.slice(some_indices, begin=i, end=i+1), dim=0))
here some_indices is a variable which I fix to be a list. Do let me know!

It looks like MXNet is not able to infer the shape of output. Did you specify the shape for variable some_indices?
e.g. some_indices = mx.sym.var('indices', shape=(1,1))
It would be nice if you can paste a minimum reproducible code :)

Instead of taking transpose, swapping among the axis resolved the issue.
def ttake( x, i ):
""" Take from axis 1 instead of 0.
"""
a = mx.sym.swapaxes(x, dim1=0, dim2=1)
return mx.sym.flatten( mx.sym.transpose( mx.sym.take( a , i ) ) )

Related

StateAccessViolation: Value must be a literal - Vyper Ethereum smart contract

Version Information
vyper Version (output of vyper --version): 0.2.8+commit.069936f
OS: osx
Python Version (output of python --version): Python 2.7.16
Environment (output of pip freeze):
altgraph==0.10.2
bdist-mpkg==0.5.0
bonjour-py==0.3
macholib==1.5.1
matplotlib==1.3.1
modulegraph==0.10.4
numpy==1.8.0rc1
py2app==0.7.3
pyobjc-core==2.5.1
pyobjc-framework-Accounts==2.5.1
pyobjc-framework-AddressBook==2.5.1
pyobjc-framework-AppleScriptKit==2.5.1
pyobjc-framework-AppleScriptObjC==2.5.1
pyobjc-framework-Automator==2.5.1
pyobjc-framework-CFNetwork==2.5.1
pyobjc-framework-Cocoa==2.5.1
pyobjc-framework-Collaboration==2.5.1
pyobjc-framework-CoreData==2.5.1
pyobjc-framework-CoreLocation==2.5.1
pyobjc-framework-CoreText==2.5.1
pyobjc-framework-DictionaryServices==2.5.1
pyobjc-framework-EventKit==2.5.1
pyobjc-framework-ExceptionHandling==2.5.1
pyobjc-framework-FSEvents==2.5.1
pyobjc-framework-InputMethodKit==2.5.1
pyobjc-framework-InstallerPlugins==2.5.1
pyobjc-framework-InstantMessage==2.5.1
pyobjc-framework-LatentSemanticMapping==2.5.1
pyobjc-framework-LaunchServices==2.5.1
pyobjc-framework-Message==2.5.1
pyobjc-framework-OpenDirectory==2.5.1
pyobjc-framework-PreferencePanes==2.5.1
pyobjc-framework-PubSub==2.5.1
pyobjc-framework-QTKit==2.5.1
pyobjc-framework-Quartz==2.5.1
pyobjc-framework-ScreenSaver==2.5.1
pyobjc-framework-ScriptingBridge==2.5.1
pyobjc-framework-SearchKit==2.5.1
pyobjc-framework-ServiceManagement==2.5.1
pyobjc-framework-Social==2.5.1
pyobjc-framework-SyncServices==2.5.1
pyobjc-framework-SystemConfiguration==2.5.1
pyobjc-framework-WebKit==2.5.1
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==1.5
pytz==2013.7
scipy==0.13.0b1
six==1.4.1
xattr==0.6.4
this call of a for loop:
for i in range(self.some_uint256):
# do something...
is throwing the error:
StateAccessViolation: Value must be a literal
full error output:
vyper.exceptions.StateAccessViolation: Value must be a literalvyper.exceptions.StateAccessViolation: Value must be a literal
contract "vyper-farm/contracts/Farm.vy", function "_employ", line 152:4
151
---> 152 for i in range(self.num_employees):
-------------^
153 pass
what exactly am i doing wrong?
is this a misunderstanding as to what a literal is on my part?
Look at the description of range-function, there just one way to pass a variable to it:
for i in range(a, a + N):
pass
In your case it should be like this (not sure that it be useful):
num_employees: public(uint256)
#external
def __init__():
self.num_employees = 16
#external
def do_smth():
for i in range(self.num_employees, self.num_employees + 10):
pass
the issue above is not one of misunderstanding the for loop's use, instead it is a result of incompatible coding style with the security measures of vyper
the reason the for loop was being created was to make sure when an 'employee' was 'fired' or 'quit' then there wouldn't be an empty record in the list of 'employee's which was being maintained
instead, in order to avoid using a for loop altogether, and with a small sacrifice of not being able to remove no longer 'active employee's, best practice is to just track the 'employee' in a hashmap:
idToEmployee: HashMap[uint256, employee]
and when tracking the employees, simply assign an id attribute to the 'employee' using a global variable called num_employees
ex:
def employ():
new_employee: employee = employee ({
id: self.num_employees
})
self.idToEmployee[self.num_employees] = new_employee
when attempting to view or update that employee's info simply use:
self.idToEmployee[id]
#vladimir has a good explanation of how range is passed variables if there is still confusion about for loops in vyper for the reader
In fact, you can't use variables in range() directly, but we can use other method.
Here is my advice:
for i in range(999999):
if i < self.some_uint256:
# do something...
else:
break

Indexing of elements in a Seq of string with chisel

I have, tab=Array(1.U, 6.U, 5.U, 2.U, 4.U, 3.U) and Y=Seq(b,g,g,g,b,g), tab is an array of UInt.
I want to do a map on tab as follows:
tab.map(case idx=>Y(idx))
But I keep getting the error: found chisel3.core.UInt, required Int.
I tried using the function peek() to convert idx to an Int by doing
tab.map(case idx=>Y(peek(idx).toInt)
but I get peek not found. I also saw that I cannot convert a chisel UInt to an Int here but did not understand the use of peek well with the example given. So please, is there another approach to do the above?
Thanks!
The immediate problem is that you cannot access the elements of scala collections using a hardware construct like UInt or SInt. It should work if you wrap Y in a Vec. Depending on your overall module this would probably look like
val YVec = VecInit(Y)
val mappedY = tab.map { case idx => YVec(idx) }

Error in mcp2matrix(model, linfct = linfct)

I don't understand why it is not working for the post hoc test. What did I do wrong?
modmisto<-lme(Cobertura~Tratamento, random=~1|Parcela, data=Cover_BraquiT3)
summary(modmisto)
tukey<-glht(modmisto, mcp(Tratamento="Tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘Tratamento’ of class ‘character’ is/are not contained as a factor in ‘model’.
Any help with this will be very appreciated!
Tratatmento does not seem to be a factor variable, try put this before:
Cover_BraquiT3$Tratamento = as.factor(Cover_BraquiT3$Tratamento)
A variable in my data.frame was of type character.
The glht function did not recognize it as a factor in the model generated by the glm function.
I Tried:
variable = as.factor (variable)
I only managed using:
library (tibble)
data <-as_tibble (data)%>%
mutate (variable = factor (variable))

LSTM with rnn cuda()?

I have the following model:
model = nn.Sequential()
model:add(nn.Sequencer(nn.LookupTable(nIndex, hiddenSize)))
model:add(nn.Sequencer(nn.FastLSTM(hiddenSize, hiddenSize, rho)))
model:add(nn.Sequencer(nn.Linear(hiddenSize, nIndex)))
model:add(nn.Sequencer(nn.LogSoftMax()))
then I put the model on cuda by:
model:cuda()
and I try to forward an input (cudatensor) and it breaks .
Is FastLSTM incompatible with cuda ?
the message:
[string "local f = function() return targets:cuda() en..."]:1: attempt to call method 'cuda' (a nil value)
I managed to introduce a few computations on cuda with the following changes:
- first put the model ans the criterion on cuda by :
model=model:cuda()
criterion=criterion:cuda()
-second I built a table of cuda tensor that I provided as targets by :
local targetscudatable={}
for i = 1, #targets do
table.insert(targetscudatable, targets[i]:cuda())
end
then it works, but I wonder if I can have more data sent to cuda, like the inputs. Anyway I already had a speed increase od 500% wich is not to bad
You forgot to require the cunn package :
require 'cunn'

Python: define a log likelihood function

Let's say I have some data z=[1,2,3,4]
I am trying to fit this data to a model which is known, so the exercise is simply to find the value of an unknown parameter D
My log likelihood function looks like this
l(D|z)= \sum(\sqrt(z^2 + D^2))
I am trying to define this log likelihood function, z is the data which is a list and theta is the parameter vector which in this case is 1 dimensional
import scipy.optimize as op
import numpy as np
D_true = some given value
def f(z,theta):
D=theta
z2=[x**2 for x in z]
return np.sqrt(np.sum(z2 + D**2))
result = op.minimize(f, D_true,args=(z))
print result.x
But I am getting the error message unsupported operand type(s) for ** or pow(): 'list' and 'int'
and pointing towards return np.sqrt(np.sum(z2 + D**2))
Can anyone help me solve this issue?
as they say, "we have eyes, if we only but see." What I mean is, it's telling you where to look
"But I am getting the error message unsupported operand type(s) for ** or pow(): 'list' and 'int'
and pointing towards return np.sqrt(np.sum(z2 + D**2))"
and it's even telling you the problem: you cannot add a list object to an int object. By the way you wrote it, I think you are assuming Python will broadcast, but it will not do that unless at least one of the objects is a numpy (ndarray) object.
You probably wanted the value D ** 2 to be added to each entry of z2. One option is to write
return np.sqrt(np.sum(z2 + D **2 * np.ones_like(z2)))
another option is
return np.sqrt(np.sum(np.array(z2) + D ** 2))
It's awkward to me to see lists being used with numpy functions, you may consider working exclusively with numpy arrays. For example, you wouldn't have run into this problem if you opted to do that from the start.
If you had a numpy array, you can use ufuncs instead of list comprehensions.
z = np.arange(1,5)
z2 = z ** 2
is the same as
z2 = [x ** 2 for x in z]
but returns a numpy array instead of a list.
I think you should replace D = theta by D, = theta since theta is a list. This way we unpack it on the fly.