Here are the examples of the python api numpy.inner taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
57 Examples
3
View Complete Implementation : copulaLDA.py
Copyright GNU General Public License v3.0
Author : balikasg
Copyright GNU General Public License v3.0
Author : balikasg
def perplexity(self):
docs = self.docs
phi = self.worddist()
log_per, N = 0, 0
Kalpha = self.K * self.alpha
for m, doc in enumerate(docs):
theta = self.n_m_z[m] / (sum([len(x) for x in doc]) + Kalpha)
for key, val in enumerate(doc):
for w in val:
log_per -= np.log(np.inner(phi[:,w], theta))
return np.exp(log_per / self.N)
3
View Complete Implementation : lda.py
Copyright GNU General Public License v3.0
Author : balikasg
Copyright GNU General Public License v3.0
Author : balikasg
def perplexity(self):
docs = self.docs
phi = self.worddist()
log_per, N = 0, 0
Kalpha = self.K * self.alpha
for m, doc in enumerate(docs):
theta = self.n_m_z[m] / (len(docs[m]) + Kalpha)
for w in doc:
log_per -= np.log(np.inner(phi[:,w], theta))
N += len(doc)
return np.exp(log_per / N)
3
View Complete Implementation : lda_sentenceLayer.py
Copyright GNU General Public License v3.0
Author : balikasg
Copyright GNU General Public License v3.0
Author : balikasg
def perplexity(self, docs=None):
if docs == None: docs = self.docs
phi = self.worddist()
log_per = 0
N = 0
Kalpha = self.K * self.alpha
for m, doc in enumerate(docs):
theta = self.n_m_z[m] / (len(doc) + Kalpha)
for sen in doc:
for w in sen:
log_per -= np.log(np.inner(phi[:,w], theta))
N += len(sen)
return np.exp(log_per / N)
3
View Complete Implementation : recursive_ls.py
Copyright MIT License
Author : birforce
Copyright MIT License
Author : birforce
def fit(self):
"""
Fits the model by application of the Kalman filter
Returns
-------
RecursiveLSResults
"""
# Get the smoother results with an arbitrary measurement variance
smoother_results = self.smooth(return_ssm=True)
# Compute the MLE of sigma2 (see Harvey, 1989 equation 4.2.5)
resid = smoother_results.standardized_forecasts_error[0]
sigma2 = (np.inner(resid, resid) /
(self.nobs - self.loglikelihood_burn))
# Now construct a results clast, where the params are the final
# estimates of the regression coefficients
self['obs_cov', 0, 0] = sigma2
return self.smooth()
3
View Complete Implementation : imitator.py
Copyright MIT License
Author : CalciferZh
Copyright MIT License
Author : CalciferZh
def compute_rodrigues(self, x, y):
"""
Compute rotation matrix R such that y = Rx.
Parameter
---------
x: Ndarray to be rotated.
y: Ndarray after rotation.
"""
theta = np.arccos(np.inner(x, y) / (np.linalg.norm(x) * np.linalg.norm(y)))
axis = np.squeeze(np.cross(x, y))
return transforms3d.axangles.axangle2mat(axis, theta)
3
View Complete Implementation : sentence.py
Copyright Apache License 2.0
Author : cap-ntu
Copyright Apache License 2.0
Author : cap-ntu
def plot_similarity(labels, features, rotation):
# plt.figure()
corr = np.inner(features, features)
sns.set(font_scale=1.2)
g = sns.heatmap(
corr,
xticklabels=labels,
yticklabels=labels,
vmin=0,
vmax=1,
cmap="YlOrRd")
g.set_xticklabels(labels, rotation=rotation)
g.set_satle("Semantic Textual Similarity")
plt.show()
3
View Complete Implementation : N-Charlie.py
Copyright GNU General Public License v3.0
Author : chbpku
Copyright GNU General Public License v3.0
Author : chbpku
def emergency_index(info): # consider time, distance
time = np.inner(info[0], info[1]) / (np.inner(info[1], info[1]) + 1e-12) # <0:approaching, >0:leaving
dist = np.linalg.norm(info[0] - time * info[1])
dist -= (info[2] + 1)
time_index = 0 if time > 0 else 1 - np.tanh(-time / 50)
dist_index = 1 / (np.exp(dist / 1.5))
# print(time,time_index)
return time_index * dist_index
3
View Complete Implementation : N-Charlie.py
Copyright GNU General Public License v3.0
Author : chbpku
Copyright GNU General Public License v3.0
Author : chbpku
def value_index(info):
time = np.inner(info[0], info[1]) / (np.inner(info[1], info[1]) + 1e-12) # <0:approaching, >0:leaving
dist = np.linalg.norm(info[0] - time * info[1])
dist -= (info[2] + 1)
time_index = 0 if time < 0 else 1 - np.tanh(-time / 50)
dist_index = 2 / (1 + np.exp(dist / 5.))
return time_index * dist_index
3
View Complete Implementation : MeshTweaker.py
Copyright GNU General Public License v3.0
Author : ChristophSchranz
Copyright GNU General Public License v3.0
Author : ChristophSchranz
def project_verteces(self, mesh, orientation):
"""Supplement the mesh array with scalars (max and median)
for each face projected onto the orientation vector.
Args:
mesh (np.array): with format face_count x 6 x 3.
orientation (np.array): with format 3 x 3.
Returns:
adjusted mesh.
"""
mesh[:, 4, 0] = np.inner(mesh[:, 1, :], orientation)
mesh[:, 4, 1] = np.inner(mesh[:, 2, :], orientation)
mesh[:, 4, 2] = np.inner(mesh[:, 3, :], orientation)
mesh[:, 5, 1] = np.max(mesh[:, 4, :], axis=1)
mesh[:, 5, 2] = np.median(mesh[:, 4, :], axis=1)
sleep(0) # Yield, so other threads get a bit of breathing space.
return mesh
3
View Complete Implementation : word2vec.py
Copyright MIT License
Author : cod3licious
Copyright MIT License
Author : cod3licious
def similarity(self, w1, w2):
"""
Compute cosine similarity between two words.
Example::
>>> trained_model.similarity('woman', 'man')
0.73723527
"""
return np.inner(self.syn0norm[self.vocab[w1].index], self.syn0norm[self.vocab[w2].index])