我需要一个正则表达式来匹配行末尾的第四个逗号,我的行以逗号结尾.
例如,我想在下面的行中选择G之后的逗号:
A,B,C,D,E,F,G,H,I,J,
Run Code Online (Sandbox Code Playgroud) 我在C ++中练习按成员分配,您可以在其中将一个对象的值设置为同一类的另一个对象。该程序的想法是用一些值初始化一个矩形对象,并创建另一个矩形对象,但是将第一个的值分配给第二个。
它给了我一个错误,在下面发布,我不知道这是什么,并且它使我发狂。
这是我的Rectangle.h
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle {
private:
double length;
double width;
public:
Rectangle(double, double);
double getLength() const;
double getWidth() const;
};
Rectangle::Rectangle(double l, double w) {
length = l;
width = w;
}
double Rectangle::getWidth() const { return width; }
double Rectangle::getLength() const { return length; }
#endif
Run Code Online (Sandbox Code Playgroud)
这是我的Rectangle.cpp
#include <iostream>
#include "rectangle.h"
using namespace std;
int main()
{
Rectangle box1(10.0, 10.0);
Rectangle box2;
cout << "box1's width and length: " << box1.getWidth() << ", …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个新列,指示前一个组中是否存在ID.这是我的数据:
data <- data.table(ID = c(1:3, c(9,2,3,4),c(5,1)),
groups = c(rep(c("a", "b", "c"), c(3, 4,2))))
ID groups
1: 1 a
2: 2 a
3: 3 a
4: 9 b
5: 2 b
6: 3 b
7: 4 b
8: 5 c
9: 1 c
Run Code Online (Sandbox Code Playgroud)
我不确定如何指定滞后组.我尝试使用shift,但它不起作用:
data[,.(ID=ID,match_lagged=ID %in% shift(ID)),by=groups]
Run Code Online (Sandbox Code Playgroud)
这是我想要的结果.
前3行不匹配,因为没有以前的组.FALSE也适用于这三行.ID = 4(在组b中)在组a中不匹配.ID = 5(在组c中)在组b中不匹配.
请注意,组c中的ID 1在组b中不匹配,因此即使它存在于组a中也应该为false.这就是为什么duplicated(data$ID)不起作用.来自组的数据必须与前一组匹配.
groups ID match_lagged
1: a 1 NA
2: a 2 NA
3: a 3 NA
4: b 9 FALSE …Run Code Online (Sandbox Code Playgroud) 如果你是一个记事本的++用户,你会明白我想让Xcode为我做什么,当我把光标放在大括号,圆括号和括号之前或之后时,我想要的非常简单,它突出了我的对,知道匹配的那些juste尝试将光标放在记事本++中并告诉我如何在Xcode中做到这一点我知道键盘右箭头的技巧和双击但是记事本++的技巧更快,提前谢谢
假设我在 Lab 颜色空间中有两种颜色-
颜色 1:L=81,a=-8,b=74
颜色 2:L=64,a=-14,b=3
我想在它们之间生成 n 种颜色。例如 n=100 或它们之间可能有尽可能多的颜色。
我知道 RGB 和 HSV 颜色渐变算法。但我想在 LAB 颜色空间中生成渐变。我不想将颜色转换为 HSV 或 RGB,因为不同的颜色模型会生成不同的渐变。
这是我发现的一个链接,它在 Lab 和其他颜色模型中生成渐变:http : //davidjohnstone.net/pages/lch-lab-colour-gradient-picker
我的目标是在 Java 中做一些类似的事情,但语言并不重要,我只需要了解它背后的逻辑和算法。
我这样做基本上是为了将扫描的颜色值与我拥有的 5 种颜色的图表相匹配。因此,我必须首先生成这 5 种颜色之间的所有颜色(使用渐变)并比较另一种颜色以找到最接近它的颜色。(为了比较,我使用 CIEDE2000 Delta-e 方法)。但我猜这是次要的。
进一步补充我的问题的最后一部分,
我想我必须生成一个渐变,因为我想在我拥有的图表序列中从我的样本中找到颜色的确切位置。
例如-我的图表中有 6 种颜色的绿色阴影(从浅到深),每种颜色都对应于 0 到 450 毫克之间的特定数字数据,如下所示(带有它们的 LAB 值)
Color 1: 78, -10, -71 [0 mg]
Color 2: 73,-14,44 [30 mg]
Color 3: 71, -19, 53 [80 mg]
Color 4: 67, -18, 31 [160 mg]
Color 5: 69, -2, …Run Code Online (Sandbox Code Playgroud) 参考匹配包,我们看一下使用的示例GenMatch.
我们读到,Weight Matrix创建的是一个矩阵,其对角线对应于X中每个变量的权重
但我们不确定生成的值代表什么 - 它们是否与标准偏差有关.
让我们举个例子 GenMatch
library(Matching)
data(lalonde)
attach(lalonde)
#The covariates we want to match on
X = cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74)
#The covariates we want to obtain balance on
BalanceMat <- cbind(age, educ, black, hisp, married, nodegr, u74, u75, re75, re74,
I(re74*re75))
#Let's call GenMatch() to find the optimal weight to give each
#covariate in 'X' so as we have achieved balance on the …Run Code Online (Sandbox Code Playgroud) 我想实现食谱及其相关成分的搜索功能。用户应该指定他想要从搜索中排除的成分,同时指定他正在寻找的食谱中包含的成分。
这是我的两个发现者:
public function findByContainingIngredients(Query $query, array $params)
{
$ingredients = preg_replace('/\s+/', '', $params['containing_ingredients']);
if($ingredients) {
$ingredients = explode(',', $ingredients);
$query->distinct(['Recipes.id']);
$query->matching('Ingredients', function ($query) use($ingredients) {
return $query->where(function ($exp, $query) use($ingredients) {
return $exp->in('Ingredients.title', $ingredients);
});
});
}
return $query;
}
public function findByExcludingIngredients(Query $query, array $params)
{
$ingredients = preg_replace('/\s+/', '', $params['excluding_ingredients']);
if($ingredients) {
$ingredients = explode(',', $ingredients);
$query->distinct(['Recipes.id']);
$query->notMatching('Ingredients', function ($query) use ($ingredients) {
return $query->where(function ($exp, $query) use ($ingredients) {
return $exp->in('Ingredients.title', $ingredients);
});
});
}
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出一种算法来查找二分图的最小顶点覆盖。
我正在考虑一个解决方案,将问题减少到二分图中的最大匹配。众所周知,可以使用从 bip 创建的网络中的最大流量来找到它。图形。
最大匹配 M 应确定最小匹配。顶点覆盖 C,但我无法处理选择顶点来设置 C。比方说 bip。图有 X、Y 部分,并且最大匹配边的端点的顶点属于集合 A,那些不属于集合 B。
我想说我应该为 M 到 C 中的一条边选择一个顶点。具体来说,M 中的边 e 的端点连接到集合 B 中的顶点,否则如果它仅连接到 A 中的顶点则没关系。不幸的是,这个想法通常不起作用,因为我的算法可以找到反例,因为 A 中的顶点也可以由除 M 中包含的边之外的其他边连接。
任何帮助将不胜感激。
这些是我可以想出的方法来尝试匹配引用计数的内部可变枚举:
#![allow(unused)]
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Debug, Clone, PartialEq)]
struct Bar {
some_bar: Vec<f64>,
}
#[derive(Debug, Clone, PartialEq)]
struct Baz {
some_baz: i32,
}
#[derive(Debug, Clone, PartialEq)]
enum Foo {
Bar(Bar),
Baz(Baz),
}
fn is_baz(foo_ref: Rc<RefCell<Foo>>) -> bool {
match foo_ref {
Foo::Bar(_) => false,
Foo::Baz(_) => true,
}
}
fn is_baz_borrow(foo_ref: Rc<RefCell<Foo>>) -> bool {
match foo_ref.borrow() {
Foo::Bar(_) => false,
Foo::Baz(_) => true,
}
}
fn is_baz_deref(foo_ref: Rc<RefCell<Foo>>) -> bool {
match *foo_ref {
Foo::Bar(_) => false,
Foo::Baz(_) …Run Code Online (Sandbox Code Playgroud) 首先:这个问题可能是重复的/已经解决的/在这个 stackoverflow 帖子中。
我想使用该MatchIt包使用马哈拉诺比斯距离在我的数据集中执行完全分块匹配。我有两个观察到的协变量(年龄和性别),我想将其用于匹配。
我知道我可以使用以下参数执行基于马哈拉诺比斯的匹配:
formula <- as.formula("group ~ sex_boolean + age")
m.out <- matchit(formula=formula,
data=data_df,
distance='mahalanobis')
site_df_matched <- get_matches(m.out,data=data_df)
Run Code Online (Sandbox Code Playgroud)
但这仅使用最近邻居执行基于马哈拉诺比斯的匹配。如果我想更严格怎么办?是否可以在马哈拉诺比斯匹配中引入卡尺?这个想法如下:对于少数群体中的每个单元,在多数群体中找到一个马哈拉诺比斯距离最小且位于定义的卡尺内的单元。如果没有来自多数群体的单元,则应丢弃来自少数群体的相应单元。
结果应该是大小相等的治疗组和对照组,其中包含各自协变量中接近的单位对。“紧密度”应该可以通过卡尺设置的严格程度来控制。更严格的卡尺将导致少数群体丢弃更多单位。
也许我对基于马哈拉诺比斯的匹配过程也有错误的理解,但是是否可以(并推荐)这样做MatchIt?
matching ×10
r ×3
algorithm ×2
associations ×1
bipartite ×1
braces ×1
c++ ×1
cakephp ×1
cakephp-3.1 ×1
colors ×1
constructor ×1
data.table ×1
dplyr ×1
duplicates ×1
enums ×1
gradient ×1
graph-theory ×1
java ×1
mahalanobis ×1
match ×1
notepad++ ×1
parentheses ×1
regex ×1
rust ×1
vertex-cover ×1
xcode ×1