Cannot understand plotting of decision boundary in SVM and LR |
Basically, you are plotting the function f : R^2 -> {0,1} so it is a
function from the 2 dimensional space into the degenerated space of only
two values - 0 and 1.
First, you generate the mesh you want to visualize your function on. In
case of your example with f(x)=y you would select some interval
[x_min,x_max] on which you would take points with some distance eps and
plot the corresponding values of f
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Next, we calculate the function values, in our case it is a SVM.predict
function, which results in either 0 or 1
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
In is the same as in
|
Fit decision boundary to logistic regression model in R |
The problem is that in exam.plot you use not only aesthetics x and y, but
also col and size (the latter unnecesarily). The layers need to have all
aesthetics set that are defined in the ggplot () call. (I've been caught
often by that problem).
Thus:
exam.plot+geom_line(data=db.data, aes(x=x, y=y), col = "black", size = 1)
does plot.
However, I'd recommend changing exam.plot a bit and removing all aesthetics
that do not apply for all layers (and put them into the layer definition
instead):
exam.plot <- ggplot(data=exam.data, aes(x = Exam1Score, y=Exam2Score))+
geom_point(aes (col = Admitted), size = 0.5)+
scale_color_manual (values = c('red', 'dark green')) +
labs(x="Exam 1 Scores", y="Exam 2 Scores", title="Exam Scores",
colour="Exam Scores")+
theme_bw()+
coord_equal
|
Simple/Single layer perceptron algorithm doesn't work |
There are at least three problems with your code:
You are redeclaring the error variable, it was first meant to be a
summarized error, then you declare it again as a per-output-neuron error,
which leads to the lose of information reagarding the whole process
Your stopping criterion is bad - it should be a mean absolute value of
errors, not just sum of errors - consider simple network, which classyfies
one training example of label 0 as 1, it will result in negative error in
your code, so training stops, even though it is far from being over
It is not true, that after training with
var inp = [
{in:[1,1], out:1},
{in:[0,0], out:0},
{in:[0,1], out:0},
];
you will get f( [1,0] ) == 0, this is not how perceptron works. It will
simply find such a line in the 2 dimensioal plane, that [
|
Looking for an efficient algorithm to find the boundary of a swept 2d shape |
If your have an arbitrarily complex shape translating and rotating along an
arbitrary path, figuring out the area swept (and its boundary) using an
exact method is going to be a really tough problem.
You might consider instead using a rendering-based approach:
start with a black canvas
densely sample the path of your moving shape
for each sample position and rotation, render the shape as white
you now have a canvas with a fairly good estimate of the swept shape
You can follow this up with these steps:
(optional) do some image processing to try to fix up any artifacts
introduced by too-sparsely sampling the path of the shape
(optional) pass the canvas through an edge-finding filter to get the
boundary of the swept shape
|
Draw straight line and create curve line dragging line |
Second touch - hold a variable to track your state.
Curve - don't try to change a path, just use the start and end of the first
line and create a UIBezierPath to draw as the user moves the touch point.
Move the bezier to the start point, then use
addCurveToPoint:controlPoint1:controlPoint2: using the end point and the
current touch location.
To make it really fun, allow the user to touch with 2 fingers while drawing
the second line and then you have values for both of the control points.
|
How can I set a blank line as a boundary to repeat a function? |
If there isn't any extra whitespace in your data, this can be accomplished
very similarly to your current approach, by adding an extra step to explode
on two newlines, and then calling your current code on each part:
$devices = $_POST['devs'];
$repeats = explode(PHP_EOL.PHP_EOL, $devices); // Favor PHP_EOL (end of
line) to avoid cross OS issues
foreach($repeats as $repeat)
{
$count = array_sum(explode(PHP_EOL, $repeat));
echo "sum is $count".PHP_EOL;
}
Obviously, if there is extra whitespace, then you'll need to do a cleanup
step first.
|
Domain boundary Line going invisible in android plot graph |
you can use
mySimpleXYPlot.setDomainBoundaries(minval,
maxval, BoundaryMode.FIXED);
where minval is the minimum value of the x axis.
and maxval is the max value on the x axis
|
Draw / Write on an image more than one line - EmguCV (OpenCV) does not recognize new line char |
You can always make your own function that parses the paragraph into
individual lines and then produce the y-displacement needed for each row.
If I remember correctly, the default font size is 16 pixels.
void myDrawMultiLineText(string InputParagraph, Point Origin)
{
vector<string> LinesOfText = myParse(InputParagraph,"
");
for (int i=0;i<LinesOfText.size(); ++i)
DrawText(CurrentLine[i], Origin.x, Origin.y + i*16);
}
|
How to Calculate and Draw Dimension Line (line with perpendicular end lines) in iOS using Core Graphics? |
The following code computes a vector of length 1 that is perpendicular to
the line from p = (x, y) to p1 = (x1, y1):
CGPoint p = CGPointMake(x, y);
CGPoint p1 = CGPointMake(x1, y1);
// Vector from p to p1;
CGPoint diff = CGPointMake(p1.x - p.x, p1.y - p.y);
// Distance from p to p1:
CGFloat length = hypotf(diff.x, diff.y);
// Normalize difference vector to length 1:
diff.x /= length;
diff.y /= length;
// Compute perpendicular vector:
CGPoint perp = CGPointMake(-diff.y, diff.x);
Now you add and subtract a multiple of that perpendicular vector to the
first point
to get the endpoints of the first marker line at p:
CGFloat markLength = 3.0; // Whatever you need ...
CGPoint a = CGPointMake(p.x + perp.x * markLength/2, p.y + perp.y *
markLength/2);
CGPoint b = CGPointMake(p.x - perp.x * mar
|
Draw a vertical line when two line charts meet - SSRS |
The green line you want to place on the chart is called a StripLine.
Getting them to display correctly can be pretty tricky. The first thing to
setup is your data structure.
The dataset results can't look like this:
Time Series Value
12:00 A 20
12:00 B 30
They must look like this:
Time SeriesAValue SeriesBValue
12:00 20 30
The reason for this is that the StripLines will not display if you try to
use Category Groups or Series Groups.
Next, you have to calculate the intercept point. In my example, I added
another dataset to return the time of the intercept.
declare @test table(Time datetime, Value1 int, Value2 int)
INSERT INTO @test values('12:00', 32, 20), ('12:01', 30, 22), ('12:02', 24,
25), ('12:03', 28, 30), ('12:04', 29, 20)
SELECT
|
Change the color of line draw line android |
Because Path itself doesn't contain any information about it's color (color
is managed by Canvas) I would suggest you to create new pair of (Path,
Paint) for every new path with different paint and use only current pair in
onTouch event. So here is some code which illustrate this idea
public class ColoredPath {
private Paint paint;
private Path path;
public ColoredPath(Paint paint, Path path) {
this.paint = paint;
this.path = path;
}
public Paint getPaint() {
return paint;
}
public Path getPath() {
return path;
}
}
private List<ColoredPath> paths = new ArrayList<ColoredPath>();
public DrawerView(Context context, AttributeSet attrs){
super(context, attrs);
//custom paint can be used here
paths.ad
|
how to split percentage of weka classifer in matlab |
here the answer of my question
the matlab code for the 10 fold cross validation is
javaaddpath('weka.jar');
import weka.core.Instances.*
import weka.classifiers.*
filename = 'c.arff';
reader = javaObject('java.io.FileReader', filename);
data = javaObject('weka.core.Instances', reader);
if (data.classIndex() == -1) % -1 means that it is undefined
data.setClassIndex(data.numAttributes() - 1);
end
c = weka.classifiers.trees.J48();
c.buildClassifier(data);
ev = weka.classifiers.Evaluation(data); % "data" here is the test data
v(1) = java.lang.String('-t');
v(2) = java.lang.String(filename);
v(3) = java.lang.String('-x');
v(4) = java.lang.String('10');
v(5) = java.lang.String('-i');
params = cat(1,v(1:end));
ev.evaluateModel(c, params)
the answer for the percentage split
|
Normal Bayes Classifer Negative Samples |
First of all, you need to decide whether you are going to do recognition.
Recognition and detection are different processes.
are you going to have 3 systems detecting cars, trucks and animals
respectively
or are you going to have 1 system detecting all of these, but also
classifying somehow with a recognition step.
Second, "animal" detection is a hard process, where "cat" detection is
easier. Please narrow down your range and make the positives similar. Check
this link for a similar problem.
Third, as you already noticed, you actually need more negatives than
positives for a proper training.
|
How to draw a line in VB.NET |
You should put this code in the Paint event of the form, what's happening
here is that the line is being drawn, but the form is re-painting as it
finishes loading, so your line disappears. Also, try a black or more
contrasting color, or you'll miss it against the window background color of
the form.
|
Perceptron problems |
There are at least few problems with your algorithm:
Your "while" conditions is wrong - the perceptron learning is not about
iterating once through all misclassified points as you do now. The
algorithm should iterate through all the points for as long as any of them
is missclassified. In particular - each update can make some correctly
classified point as the wrong one, so you have to always iterate through
all of them and check if everything is fine.
I am pretty sure that what you actually wanted is update rule in form of
(y(i)-p(i))x(i) where p(i) is predicted label and y(i) is a true label (but
this obviously degenrates to your method if you only update misclassifieds)
|
Draw line using jQuery |
You can draw using the HTML 5 canvas and straight JS:
With this HTML:
<canvas id="mycanvas" width=500></canvas>
And this Javascript:
x = 50;
y = 75
startx = 0;
starty = 75;
function drawIt() {
var c = document.getElementById("mycanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.lineWidth = "2";
ctx.strokeStyle = "blue"; // Green path
ctx.moveTo(startx, starty);
ctx.lineTo(x, y);
ctx.stroke(); // Draw it
if (x > 350) {
window.clearInterval(timerId);
} else if (y <= 25 && x >= 250) {
starty = 25;
x += 5;
} else if (y <= 75 && x >= 250) {
x = startx = 250;
y -= 5;
} else {
x += 5;
}
}
timerId = window.setInterval(drawIt, 30);
S
|
Draw a line in 3d using OpenTK |
Try to picture the line that goes from the origin (0,0,0) to (0,0,10).
It's always 0 in the x/y plane which means that if you're looking straight
at it you won't see it if the position of your "camera" is perpendicular to
the x/y plane.
If you change the "camera" position you should be able to see it.
|
JS Draw line between two or more points |
Take a look at drawing in browser SVG (Scalable Vector Graphics).
http://www.w3schools.com/svg/svg_line.asp
You can do some pretty interesting stuff with it. Go through the W3Schools
tutorial.
Let me know how it goes.
|
How to draw a path line on a map? |
I'm no expert of ruby, but in order to actually see an overlay view on a
map you need to set your class as the map's delegate and implement the –
mapView:viewForOverlay: protocol method, where you need to return the
actual MKPolyLineView object for the map to show!
In Objective C I would simply implement this method as:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <
MKOverlay >)overlay
{
if ( [overlay isKindOfClass:[MKPolyLine class]] {
MKPolyLineView *polyView = [[MKPolyLineView alloc]
initWithPolyline:overlay];
return polyView;
}
}
Hope this helps!
|
Draw line chart using dc js |
Is your data sorted by date already? Then just create a new dataset and
summarize your data there. You can find an example of a simple line chart
here:
http://bl.ocks.org/mbostock/3883245
|
SurfaceView draw line |
Each GLSurfaceView has a Render. Each Render has onDraw method(or something
like that). Acctually there are 3 methods. First one is executed to init
stage, Second one is used to Prepare the stage and Third one is for
Drawing. In this third method you have to draw a Line. Can't remember exact
method to draw a line, because using I was drawing triangles.
You said that you are creating GLSurfaceView using XML. So then you have to
use .findViewById() to get it and then add Render.
|
Vertical line not draw |
I didn't find a xml only solution.
My xml looks like. Note that the view has a fixed height which will be
replaced in the activity.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/ManualStartTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop=
|
PaperJS to draw line with arrow |
There is an example code in paperjs refrence which draws an arrow at the
end of a vector.
Have a look at: http://paperjs.org/tutorials/geometry/vector-geometry/
(scroll all the way down to the end of the page)
|
Draw line in C# sometimes has missing parts |
Since the answer of @HansPassant has also made some problems we fixed the
problem in another way:
We created an Image and filled it with an rectangle of the size of the
panel.
After that we draw the lines in the image and draw the image on the panel.
Graphics g = pnlGraph.CreateGraphics();
Image img = new Bitmap(pnlGraph.Width, pnlGraph.Height);
Graphics gi = Graphics.FromImage(img);
gi.DrawRectangle(new Pen(new SolidBrush(pnlGraph.BackColor)), new
Rectangle(0, 0, pnlGraph.Width, pnlGraph.Height));
// For every line:
gi.DrawLine(new Pen(new SolidBrush(Color.Black), 2), p1, p2);
// At the end:
g.DrawImage(img, 0, 0, img.Width, img.Height);
|
How to draw a line on a web page using dojo |
Have you tried it with Stylesheets?
Here's a fiddle : http://jsfiddle.net/kjjNY/
This is my first Div
<div id="first" style="width: 100%; height: 10px; border-bottom:2px;
border-bottom-style:solid"></div>
<div>This is my second Div</div>
<div id="second" style="width: 100%; height: 10px;
border-bottom:2px; border-bottom-style:solid"></div>
<div>This is my third Div</div>
It's the simpliest way to define a border between two divs.
Regards, Miriam
|
Draw line with varying thickness |
You can only vary the thickness of the line if you draw the line point by
point, and then vary the thickness of the points.
To find out how to draw lines point by point, look up line drawing
algorithms if you don't have them handy. One example for drawing straight
lines is Bresenham's algorithm. You can find out more about that at
http://en.wikipedia.org/wiki/Bresenham's_line_algorithm.
Then when you plot a dot, you can choose the thickness of the dot. So
instead of just drawing a single pixel, you draw a circle with radius r,
where r is the thickness of the line you want at that position in the line.
|
Android-- how to draw a line in googlemap-v2 |
Going through the Developer Guide really helps tou get started.
Anyway, what you need here is a Polyline.
|
How to programmatically draw a line in MATLAB? |
You can use the line function and set the clipping property to off to draw
a line that is visible outside the axis. The x and y coordinates of line
will be in the coordinates of the axis and you may need to change the axis
limits.
|
How do I draw a line on a Lazarus form? |
Here's what I've finally done but I'm not sure if this is the RIGHT way so
I won't accept my answer. If there's someone else who can point out any
issues with this, please let me know. I found this pretty straightforward
as well :)
Place a TGroupBox on the form.
Leave the Caption property blank. Now it should look like a panel with only
borders.
Use the mouse and drag the bottom border towards the top. Now it looks like
a line.
Well, I personally think this method is NOT efficient as it would take up
more memory space than just a real straight line. Anyway, so far it seems
to work for me :)
Here's the screenshot - look towards the bottom (just above the last text
box). The only issues is that on the sides of the line, it shows the lines
bending. I think I should set the properties cor
|
Draw a line on top of div with background image |
Have you considered using border-top? See:
#myDiv {
background-image: url('myimage.png');
background-repeat: no-repeat;
height: 32px;
width: 32px;
border-top: 10px solid red;
}
Also available on jsFiddle.
|
The best way to draw a line in windows form C# |
You can use Visual Basic Power Pack Line Shape class -
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.lineshape.aspx
Another solution using Label control
Add a Label control to your form.
Set Label Text to empty.
Set BorderStyle to Fixed3D.
Set AutoSize to false.
Set Height to 2 (most easily accomplished by typing 2 into the Size/Height
field under Label Properties).
Source : Draw horizontal divider in winforms
|
WPF InkCanvas: Draw line with DynamicRenderer |
what i think in your ondraw function your first point is fixed so it always
take it as origin so you can try this for continous drawing.
protected override void OnDraw(DrawingContext drawingContext,
StylusPointCollection stylusPoints,
Geometry geometry, Brush fillBrush)
{
drawingContext.DrawLine(pen, firstPoint,
stylusPoints.First().ToPoint());
firstPoint = stylusPoints.First().ToPoint();
}
it will update your firstpoint if you get same point exception put a check
on it ( or you can define anew point name as previous point and initially
make it equal to first point and keep it updating in your ondraw method as
i did with first point..
and if you want direct line from first point to last point you can called
you on draw m
|
Google map for IOS draw line by user |
To draw a line use polyline. Refer to Google Maps Shapes.
To use polyline you need to give locatoin coordinates. To convert a point
on screen to coordinate use coordinateForPoint:(CGPoint)point method of
GMSProjection class.
Polyline actually draws a line between two coordinates. Thus, with moving
mapView those lines will move, too. I think this is what you want.
|
How to draw line from the center of UILabel ? |
I have an idea on how you could detect the text you touch, and it actually
works, here is what i cooked up:
You add this to the label :
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTap:)];
[textLabel addGestureRecognizer:tap];
textLabel.userInteractionEnabled = YES;
[tap release];
Implementation:
- (void) handleTap:(UITapGestureRecognizer *)tap
{
CGPoint point = [tap locationInView:tap.view];
UILabel *label = (UILabel *)tap.view;
CGSize blankSize = [@" " sizeWithFont:label.font];
CGSize textSize = [label.text sizeWithFont:label.font];
if (textSize.width - point.x < 0)
{
// out of bounds
}
else
{
NSArray * array = [label.text componentsSeparatedByString:@" "
|
How to draw a line on an image in OpenCV? |
Take a look to the following solution, I firstly convert a line in polar
equations to cartesian and then I use numpy.vectorize() to generate a
vector that allows me to get represent the line in any point of the space.
import cv2
import numpy as np
img_size = (200,200)
img = np.ones(img_size) * 255
# polar equation
theta = np.linspace(0, np.pi, 1000)
r = 1 / (np.sin(theta) - np.cos(theta))
# polar to cartesian
def polar2cart(r, theta):
x = r * np.cos(theta)
y = r * np.sin(theta)
return x, y
x,y = polar2cart(r, theta)
x1, x2, y1, y2 = x[0], x[1], y[0], y[1]
# line equation y = f(X)
def line_eq(X):
m = (y2 - y1) / (x2 - x1)
return m * (X - x1) + y1
line = np.vectorize(line_eq)
x = np.arange(0, img_size[0])
y = line(x).astype(np.uint)
cv2.line(img, (x[0], y[0]), (
|
How to draw straight line between two UIButtons in iOS? |
A simple way would be to place some uiimageviews around your buttons, and
based on the ibaction of each button, add or remove images (with different
coloured lines) to/from your uiimageviews, as you need.
|
wpf how do I ensure that a line i draw isn't aliased away? |
You have to speficy
SnapsToDevicePixels="True"
in the header of your XAML
ex:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
SnapsToDevicePixels="True">
You can see the way it changes the line in this link
|
What is the minimum draw size for a line? |
WPF uses double to represent all the geometric properties (like the length
of a line). When it comes to actually outputting to the screen these will
obviously be rounded to pixels but this happens right down at the core
level. As far as you, as the programmer, need to know, you can design lines
of any length between double.MinValue and double.MaxValue (±1.8E+308)
|
How to draw a dynamic line in a control using WPF |
here is a button style for your case
<Button Height="30" MinHeight="30" MinWidth="70" Width="70"
Content="Button" FontFamily="Avenir">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="MainRectangle" Stroke="Black"
StrokeThickness="1">
<Rectangle.BitmapEffect>
<DropShadowBitmapEffect Opacity="0.2" ShadowDepth="0"/>
</Rectangle.BitmapEffect>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="1" Color="#FFAECAD2"/>
<GradientStop Offset="0" Color="#FFB9D5DD"/>
</LinearGradientBrush>
</Rectangle.Fill>
&l
|
Draw a quarter circle and a line with css |
You can just create a border with negative radius for only the top corners.
See this post for more info...
|