我需要在matlab中计算2个矩阵之间的欧氏距离.目前我正在使用bsxfun并计算距离如下(我附加了一段代码):
for i=1:4754
test_data=fea_test(i,:);
d=sqrt(sum(bsxfun(@minus, test_data, fea_train).^2, 2));
end
Run Code Online (Sandbox Code Playgroud)
fea_test的大小是4754x1024而fea_train是6800x1024,使用他的for循环导致for的执行花费大约12分钟,我认为太高了.有没有办法更快地计算两个矩阵之间的欧氏距离?
我被告知通过删除不必要的for循环,我可以减少执行时间.我也知道pdist2可以帮助减少计算时间,但由于我使用的是matlab版本7.我没有pdist2函数.升级不是一种选择.
任何帮助.
问候,
巴维亚
我正在尝试根据特定条件动态生成一组小部件。在这种情况下,我试图生成一个 RadioTiles 列表
这就是我试图生成的方式
List _listings = new List();
Widget _getListings() {
// TODO this will accept json objects in order to display the data
List listings = new List();
int i = 0;
for (i = 0; i < 5; i++) {
listings.add(
new RadioListTile<SingingCharacter>(
title: const Text('Lafayette'),
value: SingingCharacter.lafayette,
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
});
},
),
);
}
// return listings;
}
Run Code Online (Sandbox Code Playgroud)
我试图在这样的有状态小部件中显示它:
return new SafeArea(
child: Column(children: <Widget>[
new Padding( …
Run Code Online (Sandbox Code Playgroud) 我在Java中有以下代码:
public class ServerInfo {
int serverId;
int serverDataRate;
public ServerInfo(int serverId, int serverDataRate) {
this.serverId = serverId;
this.serverDataRate = serverDataRate;
}
public int getServerId() {
return serverId;
}
public double getServerDataRate() {
return serverDataRate;
}
public String toString(){
return serverId + ":" + serverDataRate;
}
}
public class ServerInfoComparator implements Comparator<ServerInfo> {
@Override
public int compare(ServerInfo o1, ServerInfo o2) {
double datarate1=o1.getServerDataRate();
double datarate2=o2.getServerDataRate();
if(datarate1>datarate2)
return -1;
else if(datarate1<datarate2)
return +1;
else
return 0;
}
}
public class Sample …
Run Code Online (Sandbox Code Playgroud) 我已经关注了链接http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld教程(使用Eclipse).并且还在这里查看了现有的stackoverflow
我使用聚合jetty 8.0.0.jar和8.1.3.jar以及servlet-api-2.5.jar.我已将这两个jar添加到类路径中,并且还包括slf4j-simple-1.6.4.jar.
我还在
`
2012-05-23 15:23:06.813:警告:oeji.nio:java.lang.NoClassDefFoundError:javax/servlet/AsyncContext
at org.eclipse.jetty.server.HttpConnection.<init>(HttpConnection.java:155)
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:19)
at org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection.<init>(SelectChannelConnector.java:309)
at org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection.<init>(SelectChannelConnector.java:303)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:286)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newConnection(SelectChannelConnector.java:364)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.<init>(SelectChannelEndPoint.java:71)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newEndPoint(SelectChannelConnector.java:274)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newEndPoint(SelectChannelConnector.java:370)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.createEndPoint(SelectorManager.java:938)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:497)
at org.eclipse.jetty.io.nio.SelectorManager$1.run(SelectorManager.java:283)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Thread.java:679)
Caused by:
java.lang.ClassNotFoundException: javax.servlet.AsyncContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.eclipse.jetty.server.HttpConnection.<init>(HttpConnection.java:155)
at org.eclipse.jetty.server.AsyncHttpConnection.<init>(AsyncHttpConnection.java:19)
at org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection.<init>(SelectChannelConnector.java:309)
at org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection.<init>(SelectChannelConnector.java:303)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newConnection(SelectChannelConnector.java:286)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newConnection(SelectChannelConnector.java:364)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.<init>(SelectChannelEndPoint.java:71)
at org.eclipse.jetty.server.nio.SelectChannelConnector.newEndPoint(SelectChannelConnector.java:274)
at org.eclipse.jetty.server.nio.SelectChannelConnector$ConnectorSelectorManager.newEndPoint(SelectChannelConnector.java:370)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.createEndPoint(SelectorManager.java:938)
at org.eclipse.jetty.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.java:497) …
Run Code Online (Sandbox Code Playgroud) 我是firebase的新手,并尝试将其用作Android应用程序存储数据的后端.数据的格式是键值对.
这是我用来存储数据的代码:
Map<Integer, PersonData> map = new HashMap<Integer, PersonData>();
map.put(PersonData.getID(), new PersonData("abcd", 12345));
Firebase ref = new Firebase(url).push();
ref.setValue(map);
Run Code Online (Sandbox Code Playgroud)
由于使用了推送引用,数据的存储方式如下:
-J5upSABqTLJ1Wfu-jFq
12345
id: 12345
name: abcd
Run Code Online (Sandbox Code Playgroud)
在哪里 - 因为我希望数据存储如下:
12345
id: 12345
name: abcd
Run Code Online (Sandbox Code Playgroud)
我不完全确定上面的代码示例是否是存储数据的正确方法.因为我希望能够在以后更新现有数据.有什么建议 ?
编辑1:我想我需要使用push,这样我就不会覆盖firebase repo中的现有数据.我刚刚尝试使用getValue()方法获取数据,我只能获取MAP中的数据
编辑2:没有使用我的参考push()方法我可以看到任何以前的数据被覆盖,只有最新的信息可用.我想知道它们是否是获得参考的更好方法,并仍然保留以前的信息
一段时间以来,我一直在尝试修改我的架构;通过更改 SpringBoot 中的模型定义。
我还有 commndLineRunner,它将用一些示例数据填充表。由于某种原因,我无法将列添加到现有表中。
我确实执行了一个 alter table 命令,这在大多数情况下都是不合理和不实用的;(这解决了一次问题;但我不想再诉诸于此)。
我感觉这与 SpringBoot MicroService 中 JPA 属性的定义有更多关系。这看起来像这样:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.hikari.maximum-pool-size=30
spring.jpa.show-sql = true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
Run Code Online (Sandbox Code Playgroud)
这是我执行 SpringBoot 应用程序时看到的错误:
Hibernate: alter table if exists public.package_definition add column no_of_email_review_requests int4 not null
Error executing DDL "alter table if exists public.package_definition add column no_of_email_review_requests int4 not null" via JDBC Statement
Caused by: org.postgresql.util.PSQLException: ERROR: column "no_of_email_review_requests" contains null values
Run Code Online (Sandbox Code Playgroud)
这是我尝试添加到我的实体中的附加列:
private int noOfEmailReviewRequests;
Run Code Online (Sandbox Code Playgroud)
编辑共享实体类:
@Entity
@Data
public class PackageDefinition {
@Id
private String id;
private SubscriptionType …
Run Code Online (Sandbox Code Playgroud) 我试图读取可变长度的用户输入并执行一些操作(比如在字符串中搜索子字符串).
问题是我不知道我的字符串有多大(文本很可能是3000-4000个字符).
我附加了我尝试的示例代码和输出:
char t[],p[];
int main(int argc, char** argv) {
fflush(stdin);
printf(" enter a string\n");
scanf("%s",t);
printf(" enter a pattern\n");
scanf("%s",p);
int m=strlen(t);
int n =strlen(p);
printf(" text is %s %d pattrn is %s %d \n",t,m,p,n);
return (EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)
输出是:
enter a string
bhavya
enter a pattern
av
text is bav 3 pattrn is av 2
Run Code Online (Sandbox Code Playgroud) 我给了一个非常大的矩阵(我不能改变矩阵的值),我需要计算(协方差)矩阵的逆.
有时我得到错误说
Matrix is close to singular or badly scaled.
Results may be inaccurate
Run Code Online (Sandbox Code Playgroud)
在这些情况下,我看到det的值返回0.
在计算逆(协方差矩阵)之前,我想检查det的值并执行类似的操作
covarianceFea=cov(fea_class);
covdet=det(covarianceFea);
if(covdet ==0)
covdet=covdet+.00001;
%calculate the covariance using this new det
end
Run Code Online (Sandbox Code Playgroud)
有没有办法使用新的det然后用它来计算协方差矩阵的逆?
我是网络开发的新手,也是使用嵌入式码头的新手.下面介绍的源代码是使用eclipse IDE开发的.我必须以编程方式启动jetty服务器,我没有通过命令行启动它的选项.它需要是一个极轻量级的Web界面,因为它将从具有低内存/处理速度的系统启动.
我在ECLIPSE中开发了以下目录结构
JettyExample <Project>
src
sample_package
HelloWorld.java
WEB-INF
index.html
web.xml
Run Code Online (Sandbox Code Playgroud)
HelloWorld.java的源代码
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setResourceBase(args.length == 2?args[1]:".");
resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });
System.out.println("serving " + resource_handler.getBaseResource());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
}
Run Code Online (Sandbox Code Playgroud)
index.html是
<html>
<head>
<title>HTML Generator Sample Page</title>
</head>
<body>
<h1 style="text-align: center;">
Agent Management Interface</h1>
<ol>
<li>
Start Platform</li>
<li>
Show Agent …
Run Code Online (Sandbox Code Playgroud) 我有一个包含以下代码的shell脚本:
dir=sample
`mkdir $dir`
`cp /home/bhavya/workspace/UnetStack/logs/log-0.txt $dir/log.txt`
`cd $dir`
Run Code Online (Sandbox Code Playgroud)
在cd
后面引号中的命令的最后一行,我无法cd
进入相应的目录.但是一旦我删除了后面的引号,我就可以了cd
.我想知道的是为什么没有cd
与后面引用的工作?