我有大约1000个维度50000的向量x_i,但它们非常稀疏; 每个只有大约50-100个非零元素.我想在这个数据集上(在MATLAB中)做PCA,以减少数据的不必要的极端维度.
不幸的是,由于需要从所有示例中减去均值,我不知道在没有中间完整矩阵的情况下如何做到这一点.当然,1000x50000矩阵太大而无法放入内存(当我尝试时,它实际上因某些原因而崩溃了我的整台计算机).princomp当我尝试使用它时,Matlab的内置程序会崩溃我的计算机.
所以我的问题是:有没有办法对这些数据进行PCA而不需要大量的非稀疏矩阵作为中间步骤?
最近,我在测试此问题:给定一组点米(全部在x轴)和一组 Ñ与端点[线的L,R ](再次在x轴),找到的最小子集n使得所有点都被一条线覆盖.证明您的解决方案始终找到最小子集.
我为它写的算法是这样的结果:(说行存储为数组,左端点位于0位,右端位于位置1)
algorithm coverPoints(set[] m, set[][] n):
chosenLines = []
while m is not empty:
minX = min(m)
bestLine = n[0]
for i=1 to length of n:
if n[i][0] <= minX and n[i][1] > bestLine[1] then
bestLine = n[i]
add bestLine to chosenLines
for i=0 to length of m:
if m[i] <= bestLine[1] then delete m[i] from m
return chosenLines
Run Code Online (Sandbox Code Playgroud)
我只是不确定这总是找到最小的解决方案.这是一个简单的贪婪算法,所以我的直觉告诉我它不会,但我的一个比我好得多的朋友说,对于这个问题,像这样的贪婪算法总能找到最小的解决方案.为了证明我的总是找到最小的解决方案我做了一个非常手的波浪证明矛盾,我做了一个假设,可能根本不是真的.我完全忘记了我的所作所为.
如果这不是一个最小的解决方案,有没有办法在比O(n!)时间更少的时间内完成它?
谢谢
我已经在Python中实现了一个版本的Rush Hour(拼图游戏)作为一些AI算法的演示.游戏并不重要,因为AI相对独立于其细节:我试图在Python中实现迭代加深深度优先搜索的版本,如下所示(请注意,此代码几乎直接从Russell和Norvig的AI文本中复制) ,第3版,对于那些了解它的人):
def depth_limited_search(game, limit):
node = GameNode(game)
frontier = []
#frontier = Queue.Queue()
frontier.append(node)
#frontier.put(node)
frontier_hash_set = set()
frontier_hash_set.add(str(node.state))
explored = set()
cutoff = False
while True:
if len(frontier) == 0:
#if frontier.empty():
break
node = frontier.pop()
#node = frontier.get()
frontier_hash_set.remove(str(node.state))
explored.add(str(node.state))
if node.cost > limit:
cutoff = True
else:
for action in node.state.get_actions():
child = node.result(action)
if str(child.state) not in frontier_hash_set and str(child.state) not in explored:
if child.goal_test():
show_solution(child)
return child.cost
frontier.append(child)
#frontier.put(child)
frontier_hash_set.add(str(child.state))
if cutoff:
return …Run Code Online (Sandbox Code Playgroud) 我正在PIC18汇编中编写一个非常基本的程序.它要求我写一个子程序来乘以两个16位数.这就是我现在所拥有的:
;***********************************************************************
; mul_16bit: subroutine that multiplies two 16 bit numbers stored in
; addresses mul_16ptr1, mul_16ptr1+1 and mul_16ptr2,mul_16ptr2+1 and
; returns the 32-bit result in addresses mul_16res1 to mul_16res1+3
;***********************************************************************
mul_16bit:
movf mul_16ptr2, W ;multiply the lower bytes
mulwf mul_16ptr1, W
movff PRODH, mul_16res+1
movff PRODL, mul_16res
movf mul_16ptr2+1, W ;multiply upper bytes
mulwf mul_16ptr1+1, W
movff PRODH, mul_16res+3
movff PRODL, mul_16res+2
movf mul_16ptr2, W ;multiply lower byte of num2
mulwf mul_16ptr1+1, W ; and upper byte of num1 …Run Code Online (Sandbox Code Playgroud) 我有一个类似于以下内容的类:
class A : std::enable_shared_from_this<A> {
public:
static std::shared_ptr<A> create() {
return std::shared_ptr<A>(new A());
}
void f() {
shared_from_this();
}
private:
A() { }
};
Run Code Online (Sandbox Code Playgroud)
它的用法类似于:
std::shared_ptr<A> pt = A::create();
pt->f();
Run Code Online (Sandbox Code Playgroud)
尽管在pt创建shared_ptr之后调用了shared_from_this()的调用,但对该调用的调用f()仍然会bad_weak_ptr引发异常。运行它可以gdb确认对的调用引发了异常,f()而不是在教师未在此处包括的某些代码中引发了异常。